Search code examples
latexvelocitytemplate-enginexelatex

How to change macro escape char in Apache Velocity


I'm using apache velocity in front of LaTeX. The # and $ escape chars are conflicting with LaTeX. I want to replace # with %% and $ with @@ to avoid the conflicts. Simply using a string replace on the source file code is not a good solution because I have to use things like #parse and #include. The parsed/included file should also be able to use the modified escape chars. Is there a way to configure this? Is there a configuration option?


Solution

  • You can use a custom resource loader to modify files loaded by #parse:

    VelocityEngine engine = new VelocityEngine();
    Properties props = new Properties();
    props.put("resource.loader", "customloader");
    props.put("customloader.resource.loader.class", CustomLoader.class.getName());
    engine.init(props);
    
    public static class CustomLoader extends FileResourceLoader {
        public InputStream getResourceStream(String arg0) throws ResourceNotFoundException {
            InputStream original = super.getResourceStream(arg0);
            //TODO modify original, return modified
            original.close();
        }
    }