Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\intertext not working as intended #102

Open
yalguzaq opened this issue Nov 18, 2022 · 0 comments
Open

\intertext not working as intended #102

yalguzaq opened this issue Nov 18, 2022 · 0 comments

Comments

@yalguzaq
Copy link

\intertext is a very popular command in LaTeX. Suppose that I have the following LaTeX code:

We cancel out 2
\begin{align*}
  2x + 2y -2 + 2 &= 2x + 2y
      \intertext{and factor out 2}
  &=2(x+y)
\end{align*}

Then pdflatex produces the following output:
image

make4ht, however, puts the text inside the equation (which is the worst possible outcome):
image

Obviously, the \intertext part must become a part of the usual HTML. Wouldn't it be possible to replace the opening \intertext{ with \end{align*} and the ending } with \begin{align*}? I once did something like this in JavaScript as a temporary solution (before I switched to make4ht):

latexml.parser.intertext = function(text) {
    for (const align of ["align", "align*"]) {
	var begin_align = text.indexOf("\\begin{"+align+"}");
	while (begin_align != -1) {
	    var end_align = text.indexOf("\\end{"+align+"}", begin_align);
	    var start = text.indexOf("\\intertext", begin_align, end_align);
	    while (start != -1) {
		var end = latexml.parser.bracketClosing(text, "{", start+9+1);
		text = text.modify("}", "\\begin{"+align+"}", end, end+1);
		text = text.replace("\\intertext{", "\\end{"+align+"}");
		start = text.indexOf("\\intertext", begin_align, end_align);
	    }
	    begin_align = text.indexOf("\\begin{"+align+"}", end_align);	    
	}
    }
    return text;
}

The main trick is, of course, preserving the alignment of &. But even if that is not possible, I think that this would be a better solution than what we have right now.

Thanks, Michal!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant