Search in sources :

Example 1 with BlockEquation

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

the class Translator method visitBlock_eqn.

@Override
public OutputModelObject visitBlock_eqn(BookishParser.Block_eqnContext ctx) {
    String eqn = stripQuotes(ctx.getText(), 3);
    if (target == Tool.Target.LATEX || target == Tool.Target.LATEX_BOOK) {
        return new BlockEquation(this, null, eqn);
    }
    String relativePath = "images/blkeqn-" + md5hash(eqn) + ".svg";
    String src = outputDir + "/" + relativePath;
    Path outpath = Paths.get(src);
    if (!Files.exists(outpath)) {
        Triple<String, Float, Float> results = texConverter.tex2svg(eqn, BLOCKEQN, 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 BlockEquation(this, relativePath, eqn);
}
Also used : BlockEquation(us.parr.bookish.model.BlockEquation) Path(java.nio.file.Path) XPath(org.antlr.v4.runtime.tree.xpath.XPath) IOException(java.io.IOException)

Aggregations

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