davemckain / snuggletex

Ancient and somewhat pathological LaTeX parser written in Java
Other
7 stars 4 forks source link

Alignment support #1

Closed philipru closed 1 year ago

philipru commented 1 year ago

Hi, just wondering if there's any way to do alignment of equals signs in SnuggleTeX or any plans to add this feature? For example \begin{aligned}a&=b+c\\a-c&=b\end{aligned}

Many thanks Philip

davemckain commented 1 year ago

Hi Philip,

Sorry for taking so long to reply!

I haven't looked at SnuggleTeX for a long time now so I've had to dig back into the code to check. It looks like I never implemented aligned. However I did implement eqnarray, so perhaps that might be an acceptable alternative?

Here's your example using eqnarray*:

\begin{eqnarray*}
a   &=& b+c\\
a-c &=& b
\end{eqnarray*}

Cheers, David

philipru commented 1 year ago

Hi Dave,

Thanks for your reply and for taking the time to look into this.

I tried your suggestion with the following code using the jar from de.rototor which is the latest version I could find on maven (sorry I couldn't find a maven artifact from your git project).

    String input = "\\begin{eqnarray*}\n" +
        "a   &=& b+c\\\\\n" +
        "a-c &=& b\n" +
        "\\end{eqnarray*}";
    SnuggleEngine engine = new SnuggleEngine();
    SnuggleSession session = engine.createSession();
    SnuggleInput snuggleInput = new SnuggleInput("$$ "+input+" $$");
    session.parseInput(snuggleInput);
    XMLStringOutputOptions options = new XMLStringOutputOptions();
    options.setSerializationMethod(SerializationMethod.XML);
    options.setEncoding("UTF-8");
    options.setIncludingXMLDeclaration(false);
    System.out.println(session.buildXMLString(options));

but the output I get is just:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"/>

Any ideas?

Many thanks Philip

davemckain commented 1 year ago

Hi Philip,

I think the problem is you've wrapped your input inside '$$' delimiters, so you're trying to open your eqnarray* environment while inside math mode, which is a parsing error.

There's some information on getting details about getting notified about parsing errors in: https://www2.ph.ed.ac.uk/snuggletex/documentation/error-reporting.html

Try doing just:

 SnuggleInput snuggleInput = new SnuggleInput(input);

That should hopefully be more successful.

(Sorry... I wrote this code a very long time ago and now can't remember very much about how it works!)

philipru commented 1 year ago

Hi Dave, Yes, removing the '$$' delimiters worked!

Thanks for all your help with this and the information about error reporting is also very handy.

Cheers Philip