这些问题如何解决呢?附件为对应的pdf文件。以下代码用xelatex编译。
\documentclass[ignorenonframetext,fleqn,handout]{beamer}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage[BoldFont,SlantFont,CJKnumber]{xeCJK}
\usepackage{listings}
%\lstset{ %
%%% language=Octave, % choose the language of the code
%% basicstyle=\footnotesize, % the size of the fonts that are used for the code
%% numbers=left, % where to put the line-numbers
%% numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
% stepnumber=2, % the step between two line-numbers. If it's 1 each line
%% % will be numbered
%% numbersep=5pt, % how far the line-numbers are from the code
%%% backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
% showspaces=false, % show spaces adding particular underscores
% showstringspaces=false, % underline spaces within strings
%% showtabs=true, % show tabs within strings adding particular underscores
%% frame=single, % adds a frame around the code
%% tabsize=2, % sets default tabsize to 2 spaces
%%% captionpos=b, % sets the caption-position to bottom
% breaklines=true, % sets automatic line breaking
% breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
%%% title=\lstname, % show the filename of files included with \lstinputlisting;
%% % also try caption instead of title
% escapeinside={\%*}{*)}, % if you want to add a comment within your code
%%% morekeywords={*,...} % if you want to add more keywords to the set
%}
%%%%%%%%%%%
%字体相关设定
%%%%%%%%%%%
\defaultfontfeatures{Scale=MatchLowercase}
\setmainfont[Mapping=tex-text]{Georgia}
\setsansfont[Mapping=tex-text]{Arial}
\setmonofont{Courier New}
%\setmainfont[Mapping=tex-text]{DejaVu Serif}
%\setsansfont[Mapping=tex-text]{DejaVu Sans}
%\setmonofont{DejaVu Sans Mono}
\setCJKmainfont{WenQuanYi Micro Hei}
\setCJKsansfont{WenQuanYi Micro Hei}
\setCJKmonofont{WenQuanYi Micro Hei Mono}
% 如果想使用多种中文字体,在这里定义
% \setCJKfamilyfont {⟨family name⟩}[<font features>]{⟨font name⟩}
\title{算法基础}
\begin{document}
\begin{frame}[t,fragile,allowframebreaks]
\frametitle{Python语言:集合,字典}
\begin{verbatim}
>>> basket = {’apple’, ’orange’, ’apple’, ’pear’, ’orange’, ’banana’}
>>> print(basket) # show that duplicates have been removed
{’orange’, ’banana’, ’pear’, ’apple’}
>>> ’orange’ in basket # fast membership testing
True
>>> ’crabgrass’ in basket
False
>>> # Demonstrate set operations on unique letters from two words
...
>>> a = set(’abracadabra’)
>>> b = set(’alacazam’)
>>> a # unique letters in a
{’a’, ’r’, ’b’, ’c’, ’d’}
>>> a - b
# letters in a but not in b
{’r’, ’d’, ’b’}
>>> a | b # letters in either a or b
{’a’, ’c’, ’r’, ’d’, ’b’, ’m’, ’z’, ’l’}
>>> a & b # letters in both a and b
{’a’, ’c’}
>>> a ^ b # letters in a or b but not both
{’r’, ’d’, ’b’, ’m’, ’z’, ’l’}
\end{verbatim}
\end{frame}
\begin{frame}[t,fragile,allowframebreaks]
\frametitle{}
\begin{lstlisting}[language=Python]
>>> basket = {’apple’, ’orange’, ’apple’, ’pear’, ’orange’, ’banana’}
>>> print(basket) # show that duplicates have been removed
{’orange’, ’banana’, ’pear’, ’apple’}
>>> ’orange’ in basket # fast membership testing
True
>>> ’crabgrass’ in basket
False
>>> # Demonstrate set operations on unique letters from two words
...
>>> a = set(’abracadabra’)
>>> b = set(’alacazam’)
>>> a # unique letters in a
{’a’, ’r’, ’b’, ’c’, ’d’}
>>> a - b
# letters in a but not in b
{’r’, ’d’, ’b’}
>>> a | b # letters in either a or b
{’a’, ’c’, ’r’, ’d’, ’b’, ’m’, ’z’, ’l’}
>>> a & b # letters in both a and b
{’a’, ’c’}
>>> a ^ b # letters in a or b but not both
{’r’, ’d’, ’b’, ’m’, ’z’, ’l’}
\end{lstlisting}
\end{frame}
\end{document}
On 3月1日, 上午11时21分, RLP <rhyslpr...@yahoo.com.cn> wrote:
> 以下可以顺利编译。前一段是verbatim环境,(问题一:)注释语句没有自动断行。后一段是listings环境,有自动断行效果,(问题二:)但是字体很丑,(问题三:)并且其中有一注释“在L前插入元素2”,显示的结果是:“在前插入元素L2”
> main.pdf
> 104K查看下载
On Wed, May 04, 2011 at 10:39:14PM +0800, Leo Liu wrote:
> 1、自动断行不可期待。verbatim、listings 这类环境设计时都假定文字不分行。分行时一般会造成难看的间距,listings 如果有背景色还会花掉。
> 2、设置 basicstyle 为你需要的字体。
> 3、最好不要在 listings 环境中使用中文。由于设计的原因,listings 环境基本不可能良好支持中文。目前如果需要正常显示中文,需要使用 escapechar 之类的功能回到普通 TeX 模式。
>
> 另:这个 mail list 看的人很少,在 CTeX 论坛提问较好。
>
--
Using GPG/PGP? Please get my current public key (ID: 0xAEF6A134,
valid from 2010 to 2013) from a key server.
�Ҽ���Դ�ļ�, ����
\documentclass{article}
\usepackage{fontspec,xunicode,xltxtra}
\usepackage{listings}
\begin{document}
\lstset{%
basicstyle=\rmfamily\small, % the size of the fonts that are used for the code
escapeinside={\%}{\%}, % if you want to add a comment within your code
}
\begin{lstlisting}[language=Python]
>>> a = set(��abracadabra��) % <==������һ��
\end{lstlisting}
\end{document}
>��˵��ò���� xelatex �� lstlistings��lstlisting �����������ֱ�������ģ�
ǰ��Leo Liu������, ��ò���escapechar�ص�latex��������������.
����,
\lstset{%
basicstyle=\rmfamily\small, % the size of the fonts that are used for the code
escapeinside={\%}{\%}, % <== ����
}
\begin{lstlisting}[language=Python]
>>> a = set(��abracadabra��) % �ص�latex: $ x^2 $ %
\end{lstlisting}
>�� CTeX ��̳���ʽϺá�
�Ǹ���̳��Ȩ���趨, ��Щ����Ҳ��ܷ���, ��һ����, mailing list��ϰ����, Ҳû����̳���ű���ķ���. ����ϰ����������ɵ�. �ҷ�����Ҳ����������