beamer and listings, verbatim的几个问题

130 views
Skip to first unread message

RLP

unread,
Feb 28, 2011, 10:21:05 PM2/28/11
to ct...@googlegroups.com
以下可以顺利编译。前一段是verbatim环境,(问题一:)注释语句没有自动断行。后一段是listings环境,有自动断行效果,(问题二:)但是字体很丑,(问题三:)并且其中有一注释“在L前插入元素2”,显示的结果是:“在前插入元素L2”

这些问题如何解决呢?附件为对应的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}

main.pdf

Vincent

unread,
Apr 28, 2011, 10:01:03 AM4/28/11
to CTeX
同问,求解释啊

On 3月1日, 上午11时21分, RLP <rhyslpr...@yahoo.com.cn> wrote:
> 以下可以顺利编译。前一段是verbatim环境,(问题一:)注释语句没有自动断行。后一段是listings环境,有自动断行效果,(问题二:)但是字体很­丑,(问题三:)并且其中有一注释“在L前插入元素2”,显示的结果是:“在前插入元素L2”

>  main.pdf
> 104K查看下载

Leo Liu

unread,
May 4, 2011, 10:39:14 AM5/4/11
to ct...@googlegroups.com
1、自动断行不可期待。verbatim、listings 这类环境设计时都假定文字不分行。分行时一般会造成难看的间距,listings 如果有背景色还会花掉。
2、设置 basicstyle 为你需要的字体。
3、最好不要在 listings 环境中使用中文。由于设计的原因,listings 环境基本不可能良好支持中文。目前如果需要正常显示中文,需要使用 escapechar 之类的功能回到普通 TeX 模式。

另:这个 mail list 看的人很少,在 CTeX 论坛提问较好。
--
您收到此邮件是因为您订阅了 Google 网上论坛的“CTeX”论坛。
要向此网上论坛发帖,请发送电子邮件至 ct...@googlegroups.com
要取消订阅此网上论坛,请发送电子邮件至 ctex+uns...@googlegroups.com
若有更多问题,请通过 http://groups.google.com/group/ctex?hl=zh-CN 访问此网上论坛。

Casper Ti. Vector

unread,
May 4, 2011, 10:48:13 AM5/4/11
to ct...@googlegroups.com
话说,貌似在 xelatex 下 lstlistings(lstlisting 环境)里可以直接用中文?

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.

RLP

unread,
May 4, 2011, 1:53:53 PM5/4/11
to ct...@googlegroups.com
лл!
�������ַ��ֵ�����쳣, a = set(��abracadabra��) һ��, ������Ϊ a=set��(��abracadabra)

�Ҽ���Դ�ļ�, ����

\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}

RLP

unread,
May 4, 2011, 1:58:20 PM5/4/11
to ct...@googlegroups.com
On 2011-05-04 Casper Ti. Vector <casper...@gmail.com> wrote:

>��˵��ò���� 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}

RLP

unread,
May 4, 2011, 2:03:15 PM5/4/11
to ct...@googlegroups.com
On 2011-05-04 Leo Liu <leoli...@gmail.com> wrote:

>�� CTeX ��̳���ʽϺá�

�Ǹ���̳��Ȩ���趨, ��Щ����Ҳ��ܷ���, ��һ����, mailing list��ϰ����, Ҳû����̳���ű���ķ���. ����ϰ����������ɵ�. �ҷ�����Ҳ����������

Leo Liu

unread,
May 4, 2011, 7:49:44 PM5/4/11
to ct...@googlegroups.com
不能。字符会乱掉。
Reply all
Reply to author
Forward
0 new messages