Xelatex 和 tikz 中奇怪的文字顏色行為

Xelatex 和 tikz 中奇怪的文字顏色行為

這是一個最小的工作範例:

\documentclass{beamer}
\usepackage{tikz}

\setbeamercolor{background canvas}{bg=black}
\setbeamercolor{normal text}{fg=white}

\begin{document}

\begin{frame}
\frametitle{Test}

Normal \textcolor{red}{Red} Normal

\begin{tikzpicture}
\node at (0,0) {Normal \textcolor{red}{Red} Normal};
\end{tikzpicture}

\end{frame}

\end{document}

編譯它pdflatex給出預期的輸出: 在此輸入影像描述

但編譯它會xelatex產生以下奇怪的行為: 在此輸入影像描述

後面的文字\textcolor{red}{Red}似乎默認返回黑色xelatex。有沒有辦法解決這個問題?

答案1

周圍也有類似的問題,例如:

主要問題是,最後\textcolor有一個\reset@color不知道要恢復的正確顏色是什麼。


當問題出現時進來了。

  1. 載入pdftex.defxetex.def根據當前編譯器。
  2. pdftex.def將定義\reset@color
    xetex.def將定義\reset@color@nostack\reset@color@stack
  3. 重新定義\reset@color.
  4. xetex.def將決定是否\reset@color@nostack\reset@color@stack將是\reset@color

這裡1,2,3發生在\documentclass{beamer}4發生在\begin{document}.

現在你可以看到一個問題:對於XeLaTeX,因為4發生在之後3reset@color被重新定義為非投影機版本。


下面的程式碼更清楚地說明了區別

\documentclass{beamer}
\usepackage{tikz}

\setbeamercolor{background canvas}{bg=teal}
\setbeamercolor{normal text}{fg=white}

\begin{document}

\frame{
    \tikz{
        \node[text=yellow]{
            Yellow
            \textcolor{red}{Red}
            What?
        };
    }
}

\end{document}

LaTeX 給出

XeLaTeX 給出

他們倆都不被期望。我們想要的是黃色。但無奈,白色比黑色好。白色確實是由 Beamer 版本完成的\reset@color,黑色是由xetex.def版本完成的。

相關內容