问题
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...
回答1:
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}")
回答2:
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}")
来源:https://stackoverflow.com/questions/13489262/latex-directives-in-template-are-causing-error-in-unicode-escape