Latex directives in template are causing `error in unicode escape`

回眸只為那壹抹淺笑 提交于 2019-12-20 06:17:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!