From 1644d70ddec8cce02ca0dc2088c2ca15257875ac Mon Sep 17 00:00:00 2001 From: Prathmesh Shukla Date: Wed, 25 Mar 2026 17:33:30 +0530 Subject: [PATCH] Fix LaTeX export for partially colored formulas using \textcolor --- TeXmacs/progs/convert/latex/latex-define.scm | 2 +- TeXmacs/progs/convert/latex/latex-drd.scm | 6 +++--- TeXmacs/progs/convert/latex/tmtex.scm | 6 ++++-- devel/203_27.md | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 devel/203_27.md diff --git a/TeXmacs/progs/convert/latex/latex-define.scm b/TeXmacs/progs/convert/latex/latex-define.scm index 8039879e61..7d0e879565 100644 --- a/TeXmacs/progs/convert/latex/latex-define.scm +++ b/TeXmacs/progs/convert/latex/latex-define.scm @@ -429,7 +429,7 @@ (tmcodeinline ((!option "") (!group (ttfamily) (!group 2)))) ;; Binary macros - (tmcolor (!group (color 1) (!group 2))) + (tmcolor (textcolor 1 2)) (tmsummarizeddocumentation (trivlist (!append (item (!option "")) (mbox "") "\\large\\bf" 1))) (tmsummarizedgrouped (trivlist (!append (item (!option "[")) (mbox "") 1))) diff --git a/TeXmacs/progs/convert/latex/latex-drd.scm b/TeXmacs/progs/convert/latex/latex-drd.scm index 6404dafdd7..5b53c9c283 100644 --- a/TeXmacs/progs/convert/latex/latex-drd.scm +++ b/TeXmacs/progs/convert/latex/latex-drd.scm @@ -116,9 +116,9 @@ (captionof "capt-of") (widthof "calc") - (color "xcolor") - (fcolorbox "xcolor") - (textcolor "xcolor") + (color "xcolor") + (fcolorbox "xcolor") + (textcolor "xcolor") (euro "eurosym") diff --git a/TeXmacs/progs/convert/latex/tmtex.scm b/TeXmacs/progs/convert/latex/tmtex.scm index 710626990e..e998b22d06 100644 --- a/TeXmacs/progs/convert/latex/tmtex.scm +++ b/TeXmacs/progs/convert/latex/tmtex.scm @@ -1591,6 +1591,8 @@ (cond ((and (== cm "none") (nnull? force-html)) (tmtex-decode-color (get-hex-color s) force-html)) ((and (== cm "HTML") (nnull? force-html)) + (when (nin? cm tmtex-colormaps) + (set! tmtex-colormaps (append (list cm) tmtex-colormaps))) `((!option "HTML") ,(html-color->latex-xcolor s))) ((== cm "texmacs") (when (nin? s tmtex-colors) @@ -1607,8 +1609,8 @@ (define (tmtex-make-color val arg) (with ltxcolor (tmtex-decode-color val #t) (if (list? ltxcolor) - `(!group (!append (color ,@ltxcolor) ,arg)) - `(tmcolor ,ltxcolor ,arg)))) + `(textcolor ,@ltxcolor ,arg) + `(textcolor ,ltxcolor ,arg)))) (define (post-process-math-text t) (cond ((or (nlist? t) (!= (length t) 2)) t) diff --git a/devel/203_27.md b/devel/203_27.md new file mode 100644 index 0000000000..bd0ee86d0d --- /dev/null +++ b/devel/203_27.md @@ -0,0 +1,16 @@ +# #3035 Fix LaTeX color export for partially styled formulas + +## 2026/03/25 Update LaTeX export for colored expressions + +### What +Updated LaTeX export for colored expressions to use \textcolor and ensured proper xcolor package handling for HTML colors. + +### Why +- Replaces fragile \color usage with scoped \textcolor, preventing color leakage +- Ensures correct behavior in both text and math mode +- Fixes missing xcolor inclusion for HTML (hex) colors + +### How +- Updated tmtex-make-color in tmtex.scm to use \textcolor +- Fixed HTML color handling in tmtex-decode-color +- Aligned macro definitions in latex-define.scm with the new approach