TransWikia.com

Putting listingsutf8 literate definitions in a separate file with input

TeX - LaTeX Asked by LimeHunter7 on March 27, 2021

I have a set of literate options for the listings package that I would like to move to an external file, so I don’t have to paste them in every time. (The eventual goal is to have LaTeX commands corresponding to all the "LaTeX-like" shortcuts in ipython, which weighs in at over 1000 definitions!)

The following MWE compiles fine for me under pdflatex from MikTeX 2.9:

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}

where the referenced input listing is

literate_test.txt

ΓΔΘΛΞΠΣΥΦΨΩαβγδζηθικλμνξπρςστυφχψωϑϕϖϰϱϴϵ

Most of the documentation I can find, including this great TeX SE question, says that the input command just pastes the input file verbatim into the current file where the command is. However, this doesn’t seem to be the case. If I try the seemingly identical example below,

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

it causes the compiler to scream Improper alphabetic constant. at me twice from somewhere within the depths of the listings package, breaking some internal function lst@CDefIt, and then overflowing the TeX stack at @@input "literate_test.txt".

Errors from TeXStudio

Other things I’ve tried include

  • Putting the literate= inside literate.tex, which causes the compiler to emit Package inputenc Error: Unicode character Γ (U+0393)(inputenc) not set up for use with LaTeX. literate={Γ, which is similar to [https://tex.stackexchange.com/q/147780/235983](this TeX SE question), except both files have the same input encoding!
  • Doing {inputencoding{utf8}input{literate.tex}}, which emits the same errors
  • Putting inputencoding{utf8} inside literate.tex, which emits the same errors

What’s going on here that prevents input from inputting the file verbatim?

EDIT: The problem is solved by putting the entire lstset in its own file. I still have no clue why this is happening though!

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP