我有一组literate
包选项listings
,我想将它们移动到外部文件中,这样我就不必每次都粘贴它们。(最终目标是让 LaTeX 命令与所有“类似 LaTeX” 的快捷方式在 ipython 中,其定义超过 1000 个!)
对于我来说,以下 MWE 在 MikTeX 2.9 的 pdflatex 下编译得很好:
literate_mwe1.tex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{amsmath}
\usepackage{listings}
\lstset{
extendedchars=true,
literate={Γ}{{\(\Gamma\)}}1 {Δ}{{\(\Delta\)}}1 {Θ}{{\(\Theta\)}}1 {Λ}{{\(\Lambda\)}}1 {Ξ}{{\(\Xi\)}}1 {Π}{{\(\Pi\)}}1 {Σ}{{\(\Sigma\)}}1 {Υ}{{\(\Upsilon\)}}1 {Φ}{{\(\Phi\)}}1 {Ψ}{{\(\Psi\)}}1 {Ω}{{\(\Omega\)}}1 {α}{{\(\alpha\)}}1 {β}{{\(\beta\)}}1 {γ}{{\(\gamma\)}}1 {δ}{{\(\delta\)}}1 {ζ}{{\(\zeta\)}}1 {η}{{\(\eta\)}}1 {θ}{{\(\theta\)}}1 {ι}{{\(\iota\)}}1 {κ}{{\(\kappa\)}}1 {λ}{{\(\lambda\)}}1 {μ}{{\(\mu\)}}1 {ν}{{\(\nu\)}}1 {ξ}{{\(\xi\)}}1 {π}{{\(\pi\)}}1 {ρ}{{\(\rho\)}}1 {ς}{{\(\varsigma\)}}1 {σ}{{\(\sigma\)}}1 {τ}{{\(\tau\)}}1 {υ}{{\(\upsilon\)}}1 {φ}{{\(\varphi\)}}1 {χ}{{\(\chi\)}}1 {ψ}{{\(\psi\)}}1 {ω}{{\(\omega\)}}1 {ϑ}{{\(\vartheta\)}}1 {ϕ}{{\(\phi\)}}1 {ϖ}{{\(\varpi\)}}1 {ϰ}{{\(\varkappa\)}}1 {ϱ}{{\(\varrho\)}}1 {ϴ}{{\(\varTheta\)}}1 {ϵ}{{\(\epsilon\)}}1
}
\begin{document}
\lstinputlisting{literate_test.txt}
\end{document}
其中引用的输入列表是
literate_test.txt
ΓΔΘΛΞΠΣΥΦΨΩαβγδζηθικλμνξπρςστυφχψωϑϕϖϰϱϴϵ
我能找到的大多数文档,包括这个很棒的 TeX SE 问题,表示该\input
命令只是将输入文件逐字粘贴到命令所在的当前文件中。然而,情况似乎并非如此。如果我尝试下面看似相同的示例,
literate_mwe2.tex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{amsmath}
\usepackage{listings}
\lstset{
extendedchars=true,
literate=\input{literate.tex}
}
\begin{document}
\lstinputlisting{literate_test.txt}
\end{document}
literate.tex
{Γ}{{\(\Gamma\)}}1 {Δ}{{\(\Delta\)}}1 {Θ}{{\(\Theta\)}}1 {Λ}{{\(\Lambda\)}}1 {Ξ}{{\(\Xi\)}}1 {Π}{{\(\Pi\)}}1 {Σ}{{\(\Sigma\)}}1 {Υ}{{\(\Upsilon\)}}1 {Φ}{{\(\Phi\)}}1 {Ψ}{{\(\Psi\)}}1 {Ω}{{\(\Omega\)}}1 {α}{{\(\alpha\)}}1 {β}{{\(\beta\)}}1 {γ}{{\(\gamma\)}}1 {δ}{{\(\delta\)}}1 {ζ}{{\(\zeta\)}}1 {η}{{\(\eta\)}}1 {θ}{{\(\theta\)}}1 {ι}{{\(\iota\)}}1 {κ}{{\(\kappa\)}}1 {λ}{{\(\lambda\)}}1 {μ}{{\(\mu\)}}1 {ν}{{\(\nu\)}}1 {ξ}{{\(\xi\)}}1 {π}{{\(\pi\)}}1 {ρ}{{\(\rho\)}}1 {ς}{{\(\varsigma\)}}1 {σ}{{\(\sigma\)}}1 {τ}{{\(\tau\)}}1 {υ}{{\(\upsilon\)}}1 {φ}{{\(\varphi\)}}1 {χ}{{\(\chi\)}}1 {ψ}{{\(\psi\)}}1 {ω}{{\(\omega\)}}1 {ϑ}{{\(\vartheta\)}}1 {ϕ}{{\(\phi\)}}1 {ϖ}{{\(\varpi\)}}1 {ϰ}{{\(\varkappa\)}}1 {ϱ}{{\(\varrho\)}}1 {ϴ}{{\(\varTheta\)}}1 {ϵ}{{\(\epsilon\)}}1
它会导致编译器Improper alphabetic constant.
从包深处的某个地方向我尖叫两次listings
,破坏一些内部功能\lst@CDefIt
,然后溢出 TeX 堆栈\@@input "literate_test.txt"
。
我还尝试过其他方法
- 将 放在
literate=
里面literate.tex
,这会导致编译器发出Package inputenc Error: Unicode character Γ (U+0393)(inputenc) not set up for use with LaTeX. literate={Γ
,这与[https://tex.stackexchange.com/q/147780/235983](这个 TeX SE 问题)类似,只是两个文件都有相同的输入编码! - 这样做
{\inputencoding{utf8}\input{literate.tex}}
会引发相同的错误 - 放入
inputencoding{utf8}
里面literate.tex
,会发出相同的错误
这里发生了什么,导致无法\input
逐字输入文件?
编辑:将整个文件放入其自己的文件中即可解决问题\lstset
。但我仍然不知道为什么会发生这种情况!