我想使用 listlisting 并发布带注释的法语源代码。这是完整的文档:
\documentclass{article}
\usepackage{listings,xcolor}
%% Langage et police utilisée
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{frame=tb,
language=Java,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=none,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true,
escapebegin={/**},
escapeend={*/},
tabsize=3
}
\begin{document}
Test écriture.
\begin{lstlisting}
/**
* Compilation problem because there is é or ç or ê or ï
* @param Description
* @return Description
*/
public static void main(String argc[]) {
System.out.println("_Compilation problem"); // This create a compilation problem
}
\end{lstlisting}
\end{document}
我有两个错误: Babel 错误
未知选项“francais”
(我尝试过 frenchb,但问题是一样的)。
第二个错误是!
软件包 inputenc 错误:Unicode 字符 �\lst@EC� (U+9EA9) ! 软件包 inputenc 错误:Unicode 字符 �\lst@EC� (U+9EA7)
...
答案1
babel
首先让我参考和的手册listings
:
babel
说
4.6 Babel 3.6 版本的变化
对法语文本排版的支持得到了极大增强;文件 francais.ldf 现在已被 Daniel Flipo 维护的 frenchb.ldf 取代。
然而,这两种选择french
都francais
可以。babel.sty
说:
\DeclareOption{francais}{\bbl@load@language{frenchb}}
\DeclareOption{french}{\bbl@load@language{frenchb}}%
listings
说(第 15 页)
因此,如果你使用支持多字节字符的包,比如用于中文和 UTF-8 字符的 CJK 或 ucs 包,你必须避免让列表处理扩展字符
但是您可以使用该选项literate
来获取输出。
\documentclass{article}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{listings,xcolor}
%% Langage et police utilisée
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\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,
}
\lstset{frame=tb,
language=Java,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=none,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true,
escapebegin={/**},
escapeend={*/},
tabsize=3
}
\begin{document}
Test écriture.
\begin{lstlisting}
/**
* Compilation problem because there is é\ or ç\ or ê\ or\ î
* @param Description
* @return Description
*/
public static void main(String argc[]) {
System.out.println("_Compilation problem"); // This create a compilation problem
}
\end{lstlisting}
\end{document}