Latex中的UTF-8(或者至less是德文变音符号)

尝试使用列表软件包将源文件包含到我的latex文档中,在代码中的注释中出现了德语变音问题。 运用

\lstset{ extendedchars=\true, inputencoding=utf8x } 

源文件中的变音符号(用UTF-8编码,没有BOM)被处理,但是它们被移动到它所包含的单词的开头。

 // die Größe muss berücksichtigt werden 

在input源文件中,变成

 // die ößGre muss übercksichtigt werden 

在输出文件中。

注:因为我发现我的初始设置错误,我大量编辑这个问题

我find了一个更简单的方法,

 \usepackage{listings} \lstset{ literate={ö}{{\"o}}1 {ä}{{\"a}}1 {ü}{{\"u}}1 } 

只有注释 ,你可以使用texcl选项:

 \lstset{language=C++,texcl=true} 

比你的意见成为乳胶,你可以使用“特殊”字符

 \begin{lstlisting} int iLink = 0x01; // Paramètre entrée \end{lstlisting} 

所以geht es(应该为其他语言工作 – 西class牙语,丹麦语)

— SNIP —

 \documentclass[ a4paper, %% defines the paper size: a4paper (default), a5paper, letterpaper, ... 12pt %% set default font size to 12 point ]{scrartcl} %% article, see KOMA documentation (scrguide.dvi) \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{listings} \lstset{language=Pascal} \lstset{literate=% {Ö}{{\"O}}1 {Ä}{{\"A}}1 {Ü}{{\"U}}1 {ß}{{\ss}}2 {ü}{{\"u}}1 {ä}{{\"a}}1 {ö}{{\"o}}1 } \begin{document} [Latex: kann man Umlaute in lstlisting verwenden?] \begin{lstlisting} Test für Umlaut äöü ÄÖÜ ß So geht es \end{lstlisting} \end{document} 

好的,现在find了一个解决方法:

  1. 而不是列表包,使用listingutf8

    \ usepackage {listingsutf8}

  2. 将listing.sty复制到文档所在的文件夹中

  3. find以下几行

      \ LST @ CCPutMacro
         \ lst @ ProcessOther {“23} \#
         \ LST @ ProcessLetter {“24} \ textdollar
         \ lst @ ProcessOther {“25} \%
         \ lst @ ProcessOther {“26} \& 
  4. 在那里input以下行(每个“注册”一个变音符号)

      \ LST @ ProcessLetter { “E4} {\” 一}
     \ LST @ ProcessLetter { “F6} {\” ○}
     \ LST @ ProcessLetter { “FC} {\” U}
     \ LST @ ProcessLetter { “C4} {\” A}
     \ LST @ ProcessLetter { “D6} {\” 啊}
     \ LST @ ProcessLetter { “DC} {\” U}
     \ LST @ ProcessLetter {“DF} {\ SS {}} 
  5. 保存文件

  6. 使用

      \ {lstset
         extendedchars = \真,
         inputencoding = UTF8 / LATIN1
     } 

启用utf8字符拉丁文字符映射

  1. 将源文件的行结束符从Windows(\ r \ n)转换为unix(\ n)
  2. 请享用

我知道这在很多方面都很难看,但是到目前为止,它是唯一对我有用的解决scheme。

我对捷克语的贡献。

 \lstset{ inputencoding=utf8, extendedchars=true, literate=% {á}{{\'a}}1 {č}{{\v{c}}}1 {ď}{{\v{d}}}1 {é}{{\'e}}1 {ě}{{\v{e}}}1 {í}{{\'i}}1 {ň}{{\v{n}}}1 {ó}{{\'o}}1 {ř}{{\v{r}}}1 {š}{{\v{s}}}1 {ť}{{\v{t}}}1 {ú}{{\'u}}1 {ů}{{\r{u}}}1 {ý}{{\'y}}1 {ž}{{\v{z}}}1 {Á}{{\'A}}1 {Č}{{\v{C}}}1 {Ď}{{\v{D}}}1 {É}{{\'E}}1 {Ě}{{\v{E}}}1 {Í}{{\'I}}1 {Ň}{{\v{N}}}1 {Ó}{{\'O}}1 {Ř}{{\v{R}}}1 {Š}{{\v{S}}}1 {Ť}{{\v{T}}}1 {Ú}{{\'U}}1 {Ů}{{\r{U}}}1 {Ý}{{\'Y}}1 {Ž}{{\v{Z}}}1 } 

我对巴西葡萄牙语的贡献。

 \lstset{% inputencoding=utf8, extendedchars=true, literate=% {é}{{\'{e}}}1 {è}{{\`{e}}}1 {ê}{{\^{e}}}1 {ë}{{\¨{e}}}1 {É}{{\'{E}}}1 {Ê}{{\^{E}}}1 {û}{{\^{u}}}1 {ù}{{\`{u}}}1 {ú}{{\'{u}}}1 {â}{{\^{a}}}1 {à}{{\`{a}}}1 {á}{{\'{a}}}1 {ã}{{\~{a}}}1 {Á}{{\'{A}}}1 {Â}{{\^{A}}}1 {Ã}{{\~{A}}}1 {ç}{{\c{c}}}1 {Ç}{{\c{C}}}1 {õ}{{\~{o}}}1 {ó}{{\'{o}}}1 {ô}{{\^{o}}}1 {Õ}{{\~{O}}}1 {Ó}{{\'{O}}}1 {Ô}{{\^{O}}}1 {î}{{\^{i}}}1 {Î}{{\^{I}}}1 {í}{{\'{i}}}1 {Í}{{\~{Í}}}1 } 

适用于大多数的iso字符。 (包括瑞典åäöÅÄÖ这是我需要的)

 \usepackage[utf8]{inputenc} \usepackage{listings} \lstset{literate= {á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1 {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 {à}{{\`a}}1 {è}{{\`e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1 {À}{{\`A}}1 {È}{{\'E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1 {ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1 {Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1 {â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1 {Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1 {œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1 {ç}{{\cc}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\ra}}1 {Å}{{\r A}}1 {€}{{\EUR}}1 {£}{{\pounds}}1 } 

来源: http : //en.wikibooks.org/wiki/LaTeX/Source_Code_Listings#Encoding_issue

为我工作得很好!

我的法国方面2美分:

 \lst@ProcessOther {"C0}{\`{A}} \lst@ProcessOther {"C1}{\'{A}} \lst@ProcessOther {"C2}{\^{A}} \lst@ProcessOther {"C4}{\"{A}} \lst@ProcessOther {"C7}{\c{C}} \lst@ProcessOther {"C8}{\`{E}} \lst@ProcessOther {"C9}{\'{E}} \lst@ProcessOther {"CA}{\^{E}} \lst@ProcessOther {"CB}{\"{E}} \lst@ProcessOther {"CE}{\^{I}} \lst@ProcessOther {"CF}{\"{I}} \lst@ProcessOther {"D4}{\^{O}} \lst@ProcessOther {"D6}{\"{O}} \lst@ProcessOther {"D9}{\`{U}} \lst@ProcessOther {"DB}{\^{U}} \lst@ProcessOther {"E0}{\`{a}} \lst@ProcessOther {"E1}{\'{a}} \lst@ProcessOther {"E2}{\^{a}} \lst@ProcessOther {"E4}{\"{a}} \lst@ProcessOther {"E7}{\c{c}} \lst@ProcessOther {"E8}{\`{e}} \lst@ProcessOther {"E9}{\'{e}} \lst@ProcessOther {"EA}{\^{e}} \lst@ProcessOther {"EB}{\"{e}} \lst@ProcessOther {"EE}{\^{\i}} \lst@ProcessOther {"EF}{\"{\i}} \lst@ProcessOther {"F4}{\^{o}} \lst@ProcessOther {"F6}{\"{o}} \lst@ProcessOther {"F9}{\`{u}} \lst@ProcessOther {"FB}{\^{u}} 

简单的方法法语。

 \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[francais]{babel} \usepackage[T1]{fontenc} \usepackage{listings} \lstloadlanguages{R} \lstset{language=R} \lstset{% inputencoding=utf8, extendedchars=true, literate=% {é}{{\'{e}}}1 {è}{{\`{e}}}1 {ê}{{\^{e}}}1 {ë}{{\¨{e}}}1 {û}{{\^{u}}}1 {ù}{{\`{u}}}1 {â}{{\^{a}}}1 {à}{{\`{a}}}1 {î}{{\^{i}}}1 {ô}{{\^{o}}}1 {ç}{{\c{c}}}1 {Ç}{{\c{C}}}1 {É}{{\'{E}}}1 {Ê}{{\^{E}}}1 {À}{{\`{A}}}1 {Â}{{\^{A}}}1 {Î}{{\^{I}}}1 } \begin{document} \begin{lstlisting} # Est-ce que ça marche : é ê è à Â Ê É Î ç Ç x<-rnorm(100,0,10) plot(density(x)) \end{lstlisting} \end{document} 

我可以证实,Janosch提供的解决scheme几乎可以正常工作。

在我的情况下,我需要使用西class牙字符:á,é,í,ó,ú,ñ,é,Í,Ó,Ú,并尝试他的解决scheme没有结果,直到我用xelatex而不是pdflatex编译我的文件。

无论如何,你应该修改listing.sty在本地副本或直接在公共文件中添加以下内容:

 \lst@CCPutMacro \lst@ProcessOther {"23}\# \lst@ProcessLetter{"24}\textdollar \lst@ProcessOther {"25}\% \lst@ProcessOther {"26}\& %spanish letters coded in UTF \lst@ProcessOther {"E1}{\'a} \lst@ProcessOther {"C1}{\'A} \lst@ProcessOther {"E9}{\'e} \lst@ProcessOther {"C9}{\'E} \lst@ProcessOther {"ED}{\'i} \lst@ProcessOther {"CD}{\'I} \lst@ProcessOther {"F3}{\'o} \lst@ProcessOther {"D3}{\'O} \lst@ProcessOther {"FA}{\'u} \lst@ProcessOther {"DA}{\'U} \lst@ProcessOther {"F1}{ñ} \lst@ProcessOther {"D1}{Ñ} 

在我的.tex文件中,我为列表使用了以下选项:

 \usepackage{listingsutf8} \lstset{ inputencoding=utf8, extendedchars=\true} 

希望它可以帮助任何人,也许我们可以构build一个包含几乎每个UTF8字符的列表。

类似于之前的post(yaxz和其他人),我为克罗地亚语定义了macros:

 % on top \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[croatian]{babel} % add listings package \usepackage{listings} % set font translations \lstset{inputencoding=utf8} \lstset{extendedchars=true} \lstset{ literate=% {ć}{{\'c}}1 {č}{{\v{c}}}1 {đ}{{\dj{}}}1 {š}{{\v{s}}}1 {ž}{{\v{z}}}1 {Ć}{{\'C}}1 {Č}{{\v{C}}}1 {Đ}{{\DJ{}}}1 {Š}{{\v{S}}}1 {Ž}{{\v{Z}}}1 } 

添加关键字“inače”仍然存在“小小”的问题。 以下内容不适用于“inače”:

 \lstset{morekeywords={ponavljaj, ako, inače, dok}} 

关键字“inače”(出现在代码中)不被识别为关键字。 有任何想法吗?

希望这会帮助别人(除了我:))。

瑞典版本:

 \lstset{literate=% {å}{{\r{a}}}1 {ä}{{\"a}}1 {ö}{{\"o}}1 {Å}{{\r{A}}}1 {Ä}{{\"A}}1 {Ö}{{\"O}}1 } 

我对立陶宛语的贡献:

 \lstset{% literate=% {ą}{{\k{a}}}1 {č}{{\v{c}}}1 {ę}{{\k{e}}}1 {ė}{{\.{e}}}1 {į}{{\k{i}}}1 {š}{{\v{s}}}1 {ų}{{\k{u}}}1 {ū}{{\={u}}}1 {ž}{{\v{z}}}1 {Ą}{{\k{A}}}1 {Č}{{\v{C}}}1 {Ę}{{\k{E}}}1 {Ė}{{\.{E}}}1 {Į}{{\k{I}}}1 {Š}{{\v{S}}}1 {Ų}{{\k{U}}}1 {Ū}{{\={U}}}1 {Ž}{{\v{Z}}}1 } 

包的作者build议使用texcl选项。 有时候会有帮助,有时候不会。

最简洁的解决scheme是使用listing2包: http : //www.atscire.de/index.php? nav=products/listings2

只需使用\usepackage{listings2}而不是\usepackage{listings}

@ Janosch解决scheme中的listing.sty的挪威语信件:

 \lst@ProcessLetter{"C5}{\AA} \lst@ProcessLetter{"C6}{\AE} \lst@ProcessLetter{"D8}{\O} \lst@ProcessLetter{"E5}{\aa} \lst@ProcessLetter{"E6}{\ae} \lst@ProcessLetter{"F8}{\o} 

越南语:

 \usepackage{vntex} \usepackage[utf8]{inputenc} \usepackage{listings} \usepackage{tipa} \lstset{columns=fullflexible,literate= {đ}{{\dj}}1 {â}{{\^a}}1 {ă}{{\u{a}}}1 {ê}{{\^e}}1 {ô}{{\^o}}1 {ơ}{{\ohorn}}1 {ư}{{\uhorn}}1 {á}{{\'a}}1 {à}{{\`a}}1 {ả}{\h{a}}1 {ã}{{\~a}}1 {ạ}{\textsubdot{a}}1 {ấ}{\'{\^a}}1 {ầ}{\`{\^a}}1 {ẩ}{\h{\^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工作!):

 \usepackage[greek]{babel} \usepackage{textgreek} \usepackage{listings} % Notice that here it is spelled 'omikron', not 'omicron', % and that I use '\textmugreek' instead of '\textmu', % which are both part of the textgreek package, but the % 'normal' \textmu conflicts with the textcomp package as % that uses another font for \textmu. \DeclareUnicodeCharacter{03BF}{\textomikron} \DeclareUnicodeCharacter{039F}{\textOmikron} \DeclareUnicodeCharacter{03BC}{\textmugreek} \lstset{ inputencoding=utf8, extendedchars=true, literate= {α}{{\textalpha}}1 {Α}{{\textAlpha}}1 {β}{{\textbeta}}1 {Β}{{\textBeta}}1 {γ}{{\textgamma}}1 {Γ}{{\textGamma}}1 {δ}{{\textdelta}}1 {Δ}{{\textDelta}}1 {ε}{{\textepsilon}}1 {Ε}{{\textEpsilon}}1 {ζ}{{\textzeta}}1 {Ζ}{{\textZeta}}1 {η}{{\texteta}}1 {Η}{{\textEta}}1 {θ}{{\texttheta}}1 {Θ}{{\textTheta}}1 {ι}{{\textiota}}1 {Ι}{{\textIota}}1 {κ}{{\textkappa}}1 {Κ}{{\textKappa}}1 {λ}{{\textlambda}}1 {Λ}{{\textLambda}}1 {μ}{{\textmugreek}}1 {Μ}{{\textMu}}1 {ν}{{\textnu}}1 {Ν}{{\textNu}}1 {ξ}{{\textxi}}1 {Ξ}{{\textXi}}1 {ο}{{\textomikron}}1 {Ο}{{\textOmikron}}1 {π}{{\textpi}}1 {Π}{{\textPi}}1 {ρ}{{\textrho}}1 {Ρ}{{\textRho}}1 {σ}{{\textsigma}}1 {Σ}{{\textSigma}}1 {ς}{{\textvarsigma}}1 {τ}{{\texttau}}1 {Τ}{{\textTau}}1 {υ}{{\textupsilon}}1 {Υ}{{\textUpsilon}}1 {φ}{{\textphi}}1 {Φ}{{\textPhi}}1 {χ}{{\textchi}}1 {Χ}{{\textChi}}1 {ψ}{{\textpsi}}1 {Ψ}{{\textPsi}}1 {ω}{{\textomega}}1 {Ω}{{\textOmega}}1 } 

对于冰岛人:

 \lstset{ literate=% {Á}{{\'A}}1 {á}{{\'a}}1 {Ð}{{\dh}}1 {ð}{{\dh}}1 {É}{{\'E}}1 {é}{{\'e}}1 {í}{{\'i}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {ó}{{\'o}}1 {Ú}{{\'U}}1 {ú}{{\'u}}1 {Ý}{{\'Y}}1 {ý}{{\'y}}1 {Þ}{{\TH}}1 {þ}{{\th}}1 {Æ}{{\AE}}1 {æ}{{\ae}}1 {Ö}{{\"O}}1 {ö}{{\"o}}1 } 

如果您想使用任何列表软件包,只需在LaTex中不使用UTF-8。 在文档中使用latin1会显示德语变音符号。

我正在用德文写我的论文:

 % Your language, here German \usepackage[ngerman]{babel} % Will work with Umlauts \usepackage[latin1]{inputenc} % Euro characters etc. \usepackage{textcomp} % Works perfectly with latin1 \usepackage{listings} 

您可能需要将文档的input编码设置为UTF-8。 有一个comp.text.tex线程讨论如何做到这一点。 以下是在GNU / Linux上的TeXLive中完成的:

 \usepackage[utf8]{inputenc}