我使用 babel 包来用“kerkis”字体书写希腊语。
我想在我的乳胶文档中添加英文代码(“courier new”字体),但是遇到了一些困难。
有人能帮助我吗?提前谢谢。
\documentclass[12pt]{article}
\usepackage[english,greek]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{graphicx}
\usepackage{fancybox}
\usepackage{verbatim}
\usepackage{courier}
\usepackage{kerkis}
\usepackage{float}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tocloft}
\usepackage{hyperref}
\usepackage{afterpage}
\usepackage{color}
\usepackage{listings}
\renewcommand{\lstlistingname}{Κώδικας}
\lstset{
%matlab
backgroundcolor=\color{white},
basicstyle=\normalsize, % COURIER NEW?
commentstyle=\color{green}, % comment style
escapeinside={\%*}{*)},
extendedchars=true,
frame=single,
keywordstyle=\color{blue}, % keyword style
numbers=left,
numbersep=5pt,
numberstyle=\normalsize\color{black},
rulecolor=\color{black},
stepnumber=1,
stringstyle=\color{magenta}, % string style
}
\begin{document}
\selectlanguage{greek}
Ελληνικά: \textlatin{this word means greek}
\selectlanguage{english}
Now I write in english
\selectlanguage{greek}
Ελληνικά
%\selectlanguage{english}???
\begin{lstlisting}[caption = \textlatin{example1.m}]
{
% Entropy
E = 0;
for i = 1:J
if p(i) ~= 0
E = E + p(i)*log2(1/p(i));
end
end
}
\end{lstlisting}
\end{document}
答案1
你需要
- 激活英语
- 切换到文档的等宽字体(因为您已经加载了该
courier
包,所以是 Courier)
在传递给键的值中basicstyle
,如下所示:
basicstyle=\selectlanguage{english}\ttfamily,
请注意,如果希腊语是活跃的前上市后,希腊仍将保持活跃后列表,因为传递给该值的所有声明basicstyle
都是列表本地的。
\documentclass[12pt]{article}
\usepackage[english,greek]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{graphicx}
\usepackage{fancybox}
\usepackage{verbatim}
\usepackage{kerkis}
\usepackage{float}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tocloft}
\usepackage{hyperref}
\usepackage{courier}
\usepackage{afterpage}
\usepackage{color}
\usepackage{listings}
\renewcommand{\lstlistingname}{Κώδικας}
\lstset{
%matlab
backgroundcolor=\color{white},
basicstyle=\normalsize\selectlanguage{english}\ttfamily, % COURIER NEW?
commentstyle=\color{green}, % comment style
escapeinside={\%*}{*)},
extendedchars=true,
frame=single,
keywordstyle=\color{blue}, % keyword style
numbers=left,
numbersep=5pt,
numberstyle=\normalsize\color{black},
rulecolor=\color{black},
stepnumber=1,
stringstyle=\color{magenta}, % string style
}
\begin{document}
\selectlanguage{greek}
Ελληνικά: \textlatin{this word means greek}
\selectlanguage{english}
Now I write in english
\selectlanguage{greek}
Ελληνικά
%\selectlanguage{english}???
\begin{lstlisting}[caption = \textlatin{example1.m}]
{
% Entropy
E = 0;
for i = 1:J
if p(i) ~= 0
E = E + p(i)*log2(1/p(i));
end
end
}
\end{lstlisting}
Ελληνικά: \textlatin{this word means greek}
\selectlanguage{english}
Now I write in english
\selectlanguage{greek}
Ελληνικά
\end{document}