LaTeXML icon indicating copy to clipboard operation
LaTeXML copied to clipboard

color from surrounding scope overrides colors inside boxes

Open xworld21 opened this issue 11 months ago • 2 comments

This was quite difficult to pin down. Emitting a box apparently inherits the surrounding colour, overriding whatever happens in the box.

\documentclass{article}
\newbox\mybox
\usepackage{xcolor}
\begin{document}
  \color{black}

  \global\setbox\mybox=\vbox{The final word should be \textcolor{green}{green}}
  \box\mybox
\end{document}

You get

<document xmlns="http://dlmf.nist.gov/LaTeXML">
  <resource src="LaTeXML.css" type="text/css"/>
  <resource src="ltx-article.css" type="text/css"/>
  <para vattach="bottom" xml:id="p1">
    <p><text color="#000000">The final word should be green</text></p>
  </para>
</document>

If I remove \color{black}, I get the expected

<document xmlns="http://dlmf.nist.gov/LaTeXML">
  <resource src="LaTeXML.css" type="text/css"/>
  <resource src="ltx-article.css" type="text/css"/>
  <para vattach="bottom" xml:id="p1">
    <p>The final word should be <text color="#00FF00">green</text></p>
  </para>
</document>

(Context: I am experimenting with reading beamer raw. Against all odds, it actually works, except that all colours are missing due to this bug!)

xworld21 avatar Dec 23 '24 17:12 xworld21

Ah, now that I know what the bug is, I can also find the source: https://github.com/brucemiller/LaTeXML/blob/13018504e00ba934bc067357c372b72951227494/lib/LaTeXML/Engine/TeX_Box.pool.ltxml#L552-L556 This function should skip the boxes whose colour is already specified.

xworld21 avatar Dec 23 '24 18:12 xworld21

@xworld21 just a brief comment - I believe the last 3 issues you've opened in the LaTeXML repository may be the best 3 issues to have ever been opened here. Precise reporting, minimal examples and with exact code references, I'm genuinely impressed. You're making our lives very easy!

It took me very little effort to make sample PRs addressing the issues.

dginev avatar Dec 24 '24 02:12 dginev