diff --git a/TeXmacs/plugins/latex/progs/convert/latex/tmtex.scm b/TeXmacs/plugins/latex/progs/convert/latex/tmtex.scm index f96afe4b9c..d39622f709 100644 --- a/TeXmacs/plugins/latex/progs/convert/latex/tmtex.scm +++ b/TeXmacs/plugins/latex/progs/convert/latex/tmtex.scm @@ -1588,10 +1588,10 @@ (define (tmtex-decode-color s . force-html) (with cm (if (string-starts? s "#") "HTML" (named-color->xcolormap s)) - (cond ((and (== cm "none") (nnull? force-html)) + (cond ((== cm "HTML") + (string-append "#" (html-color->latex-xcolor s))) + ((and (== cm "none") (nnull? force-html)) (tmtex-decode-color (get-hex-color s) force-html)) - ((and (== cm "HTML") (nnull? force-html)) - `((!option "HTML") ,(html-color->latex-xcolor s))) ((== cm "texmacs") (when (nin? s tmtex-colors) (set! tmtex-colors (append (list s) tmtex-colors))) @@ -1607,7 +1607,7 @@ (define (tmtex-make-color val arg) (with ltxcolor (tmtex-decode-color val #t) (if (list? ltxcolor) - `(!group (!append (color ,@ltxcolor) ,arg)) + `(!group (!append (color ,@ltxcolor) (!group ,arg))) `(tmcolor ,ltxcolor ,arg)))) (define (post-process-math-text t) diff --git a/TeXmacs/progs/convert/latex/tmtex.scm b/TeXmacs/progs/convert/latex/tmtex.scm index 710626990e..f9ec2cf5ed 100644 --- a/TeXmacs/progs/convert/latex/tmtex.scm +++ b/TeXmacs/progs/convert/latex/tmtex.scm @@ -1588,10 +1588,10 @@ (define (tmtex-decode-color s . force-html) (with cm (if (string-starts? s "#") "HTML" (named-color->xcolormap s)) - (cond ((and (== cm "none") (nnull? force-html)) + (cond ((== cm "HTML") + (string-append "#" (html-color->latex-xcolor s))) + ((and (== cm "none") (nnull? force-html)) (tmtex-decode-color (get-hex-color s) force-html)) - ((and (== cm "HTML") (nnull? force-html)) - `((!option "HTML") ,(html-color->latex-xcolor s))) ((== cm "texmacs") (when (nin? s tmtex-colors) (set! tmtex-colors (append (list s) tmtex-colors))) @@ -1607,7 +1607,7 @@ (define (tmtex-make-color val arg) (with ltxcolor (tmtex-decode-color val #t) (if (list? ltxcolor) - `(!group (!append (color ,@ltxcolor) ,arg)) + `(!group (!append (color ,@ltxcolor) (!group ,arg))) `(tmcolor ,ltxcolor ,arg)))) (define (post-process-math-text t) diff --git a/TeXmacs/tests/203_27.scm b/TeXmacs/tests/203_27.scm new file mode 100644 index 0000000000..8739139e2b --- /dev/null +++ b/TeXmacs/tests/203_27.scm @@ -0,0 +1,45 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; MODULE : 203_27.scm +;; DESCRIPTION : Unit tests for partial color LaTeX export +;; COPYRIGHT : (C) 2026 AcceleratorX +;; +;; This software falls under the GNU general public license version 3 or later. +;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE +;; in the root directory or . +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(import (liii check)) + +(check-set-mode! 'report-failed) + +(define (normalize-latex latex) + (set! latex (string-replace latex "\r\n" "\n")) + (set! latex (string-replace latex "\r" "")) + (set! latex (string-replace latex "\n" "")) + (set! latex (string-replace latex "\t" "")) + (string-replace latex " " "")) + +(define (test-export-latex-partial-color) + (use-modules + (data latex) + (data tmu)) + (let* ((tmu-doc (string-load "$TEXMACS_PATH/tests/tmu/203_27.tmu")) + (latex (normalize-latex + (texmacs->latex-document (tmu->texmacs tmu-doc) '())))) + (check (string-contains? latex "\\color{red}{ddd}") => #t) + (check (string-contains? latex + (string-append "\\color{" "#" "AA6666}{ddd}")) + => #t) + (check (string-contains? latex "\\color{blue}{ddd}") => #t) + (check (string-contains? latex + (string-append "\\color[HTML]{" "AA6666}")) + => #f) + (check (string-contains? latex + (string-append "\\color{" "#" "AA6666}ddd")) + => #f))) + +(tm-define (test_203_27) + (test-export-latex-partial-color) + (check-report)) diff --git a/TeXmacs/tests/tmu/203_27.tmu b/TeXmacs/tests/tmu/203_27.tmu new file mode 100644 index 0000000000..a8302c1a80 --- /dev/null +++ b/TeXmacs/tests/tmu/203_27.tmu @@ -0,0 +1,25 @@ +> + +> + +<\body> + <\equation*> + d d d + + + <\equation*> + d d d + + + <\equation*> + d d d + + + + +<\initial> + <\collection> + + + + diff --git a/devel/203_27.md b/devel/203_27.md new file mode 100644 index 0000000000..ab9e5beb14 --- /dev/null +++ b/devel/203_27.md @@ -0,0 +1,22 @@ +# [203_27] 公式带前景色时,使用部分颜色时导出 LaTeX 代码会出错 + +## 如何测试 + +1. 打开测试文件 `TeXmacs/tests/tmu/203_27.tmu`,复制其中公式到 LaTeX,预期效果: +``` +\[ {\color{red}{d d d}} d d d \] +\[ {\color{#AA6666}{d d d}} d d d \] +\[ {\color{blue}{d d d}} d d d \] +``` + +原本复制到 LaTeX 效果 +``` +\[ {\color{red}{d d d}} d d d \] +\[ {\color[HTML]{AA6666}d d d} d d d \] +\[ {\color{blue}{d d d}} d d d \] +``` + +2. 集成测试文件在 `TeXmacs/tests/203_27.scm` +``` +xmake run 203_27 +``` \ No newline at end of file