Latex directives in template are causing `error in

2019-03-03 08:15发布

I want to include some LaTEX code in play framework 2.0 template, namely:

\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}

Of course play complains with error in unicode escape error message because of \us... parts.

How should I escape those pieces of text, so play compiles the template and I get verbatim LaTeX code in result? Tried my luck with @Html(), but it doesn't work either...

2条回答
祖国的老花朵
2楼-- · 2019-03-03 09:01

Create an method ie in Application.java controller:

public static String latex(String s){
    return "\\"+s;
}

So you can use it in the view:

@Application.latex("usepackage[T1]{fontenc}")
@Application.latex("usepackage[latin9]{inputenc}")
@Application.latex("usepackage{babel}")
查看更多
闹够了就滚
3楼-- · 2019-03-03 09:12

Or, based on @biesior answer, create a latex.scala.html file containing:

@(latexStatement:String)

@{
    "\\" + latexStatement
}

To use it:

@latex("usepackage[T1]{fontenc}")
@latex("usepackage[latin9]{inputenc}")
@latex("usepackage{babel}")
查看更多
登录 后发表回答