Search in sources :

Example 1 with Latex

use of us.parr.bookish.model.Latex in project bookish by parrt.

the class Translator method visitLatex.

@Override
public OutputModelObject visitLatex(BookishParser.LatexContext ctx) {
    String text = ctx.getText().trim();
    // \latex{{...}}
    List<String> stuff = extract(latexPattern, text);
    text = stuff.get(0);
    if (target == Tool.Target.LATEX || target == Tool.Target.LATEX_BOOK) {
        return new Latex(this, null, text, text);
    }
    String relativePath = "images/latex-" + md5hash(text) + ".svg";
    String src = outputDir + "/" + relativePath;
    Path outpath = Paths.get(src);
    if (!Files.exists(outpath)) {
        Triple<String, Float, Float> results = texConverter.tex2svg(text, LATEX, BLOCK_EQN_FONT_SIZE);
        String svg = results.a;
        try {
            System.out.println(outpath);
            Files.write(outpath, svg.getBytes());
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
    return new Latex(this, relativePath, text, text);
}
Also used : Path(java.nio.file.Path) XPath(org.antlr.v4.runtime.tree.xpath.XPath) IOException(java.io.IOException) Latex(us.parr.bookish.model.Latex)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 XPath (org.antlr.v4.runtime.tree.xpath.XPath)1 Latex (us.parr.bookish.model.Latex)1