診斷 pythontex 和 siam .cls 檔案之間的不相容性

診斷 pythontex 和 siam .cls 檔案之間的不相容性

我在 SIAM 提供的文檔類中使用 pythontex (請參閱http://www.siam.org/meetings/ns14/siam-wns-article.cls- 2014 年版本不到 100 行,與 2018 年版本有相同的問題)。

當我編譯時

\documentclass{siam-wns-article}
\usepackage{pythontex}


\begin{document}
test
\end{document}

我收到錯誤:

\c@listing=\count122

./tmp.tex:5: 你不能在 \the 之後使用 `\relax'。

\c@float@type

我的實際範例的輸出很好。但錯誤仍然存在,會議組織者表示,他們將需要最終會議的原始 tex 文件。所以我想確保我可以告訴他們文檔類別中需要修復什麼。但我一直無法弄清楚。

有什麼建議麼?

答案1

問題描述如下https://github.com/gpoore/pythontex/issues/61https://github.com/axelsommerfeldt/caption/issues/5

解決方法:為 PythonTeX 浮點使用不同的名稱(無論是否使用它們,都獨立)。

\documentclass{siam-wns-article}
\usepackage{pythontex}

\setpythontexlistingenv{pylisting}

\begin{document}
test
\end{document}

問題的解釋。包newfloat測試是否\c@float@type被定義\ifdefined,這是錯誤的:它應該使用\@ifundefined.listings載入時出現問題,因為這個包use \@ifundefined{c@float@type},它\c@float@type等於\relax然後\ifdefined\c@float@type回傳 true。您正在使用的 SIAM 類別會載入listings

中的一個錯誤newfloat

答案2

作為大衛答案的替代方案,如果您可以修改類別文件。

問題似乎來自於pythontex和之間的不相容性listings(後者由您的類別文件載入)。

正如該問題的 GitHub 頁面的評論之一所述,在解決問題pythontex之前加載listings(或根本不加載列表:)。

所以放在pythontex前面listings就可以了。

答案3

錯誤訊息表示計數器float@type未定義

grep 'newcounter.*float@type' /usr/local/texlive/2017/texmf-dist/tex/latex/*/*.*

出現float.sty,因此可能的解決方法是

\documentclass{siam-wns-article}
\usepackage{float}
\usepackage{pythontex}


\begin{document}
test
\end{document}

運行沒有錯誤。

不過,我注意到 pythontex 加載 newfloat 所以這可能不是最好的解決方案,因為您可能並不真正希望 float 和 newfloat 都加載,而另一個答案指向了一個線索,然後一些跟踪表明這是常見問題Latex 測試的\@ifundefined{c@float@typ}副作用\c@float@type\relax由於原語的一個奇怪的特徵而定義的\csname

碰巧下一個版本的 Latex 可能會有程式碼來避免這個問題,但同時你可以設定\c@float@type回未定義狀態

\documentclass{siam-wns-article}

\AtBeginDocument{%
\expandafter\ifx\csname c@float@type\endcsname\relax
\expandafter\let\csname c@float@type\endcsname\undefined
\fi
}
\usepackage{pythontex}



\begin{document}
test
\end{document}

相關內容