Redian新闻
>
怎样用latex编排C语言源代码?
avatar
怎样用latex编排C语言源代码?# TeX - TeX电子排版系统
l*r
1
我用latex写了一个presentation,关于C语言编程的. 数学模式下格式很好弄。但在文本
模式下,怎么加缩进符号啊?
avatar
z*n
2
\begin{verbatim}
\end{verbatim}
or use package{listing} for more professional output.



【在 l********r 的大作中提到】
: 我用latex写了一个presentation,关于C语言编程的. 数学模式下格式很好弄。但在文本
: 模式下,怎么加缩进符号啊?

avatar
T*n
3
The inventor of TeX, Donald Knuth, also wrote a program called "CWEB".
It consists of two main programs, "cweave" and "ctangle".
A programmer would write a C program, along with detailed documentation,
in the syntax of CWEB (which I think is a bit awkward, but you get used
to it if you use it lot). Then you can run cweave on the CWEB file to
produce a TeX (not LaTeX) source file, or run ctangle on the CWEB file
to produce the C source with all the documentation stripped out.
The best way to und

【在 l********r 的大作中提到】
: 我用latex写了一个presentation,关于C语言编程的. 数学模式下格式很好弄。但在文本
: 模式下,怎么加缩进符号啊?

avatar
T*e
4
if you already have the C code in a file, you can include verbatim package and
simply do:
\verbatiminput{yourcode.c}

【在 T*******n 的大作中提到】
: The inventor of TeX, Donald Knuth, also wrote a program called "CWEB".
: It consists of two main programs, "cweave" and "ctangle".
: A programmer would write a C program, along with detailed documentation,
: in the syntax of CWEB (which I think is a bit awkward, but you get used
: to it if you use it lot). Then you can run cweave on the CWEB file to
: produce a TeX (not LaTeX) source file, or run ctangle on the CWEB file
: to produce the C source with all the documentation stripped out.
: The best way to und

avatar
f*h
5
a follow-up question, is there anyway to specify the maximum number
of characters a line can have, say 80, in a source code file. Or,
how to do auto-wrapping.

and

【在 T*******e 的大作中提到】
: if you already have the C code in a file, you can include verbatim package and
: simply do:
: \verbatiminput{yourcode.c}

avatar
l*r
6
我把C语言源代码放在 \begin{verbatim} 和\end{verbatim}之间。大部分都好,可是双
引号显示不出来? 怎么办呢?

【在 f********h 的大作中提到】
: a follow-up question, is there anyway to specify the maximum number
: of characters a line can have, say 80, in a source code file. Or,
: how to do auto-wrapping.
:
: and

avatar
z*n
7
how come?



【在 l********r 的大作中提到】
: 我把C语言源代码放在 \begin{verbatim} 和\end{verbatim}之间。大部分都好,可是双
: 引号显示不出来? 怎么办呢?

avatar
T*e
8
from my experience, the built-in verbatim environment from Latex has
all kinds of strange problems. I always include \usepackage{verbatim}
before using it.

【在 z*****n 的大作中提到】
: how come?
:
: 双

avatar
T*n
9
That shouldn't happen. What class and packages have you loaded?
If you just create a minimal document with " in a verbatim environment,
does the problem occur?
Also I'm wondering whether this might be a font encoding issue.
Are you using a difference font that cmtt (the default in LaTeX), and
are you loading the fontenc or t1enc or other similar packages?



【在 l********r 的大作中提到】
: 我把C语言源代码放在 \begin{verbatim} 和\end{verbatim}之间。大部分都好,可是双
: 引号显示不出来? 怎么办呢?

avatar
z*n
10
I got one problem in verbatim environment: the table indents cannot be d
isplayed and all lines starts from the
beginning of left inside \verbatim.
Another problem is that both verbatim and listings cannot
automatically wrap the too-long lines, thus always make the output messy
.

【在 T*******e 的大作中提到】
: from my experience, the built-in verbatim environment from Latex has
: all kinds of strange problems. I always include \usepackage{verbatim}
: before using it.

avatar
z*n
11

especially when using \verbatiminput command.

【在 z*****n 的大作中提到】
: I got one problem in verbatim environment: the table indents cannot be d
: isplayed and all lines starts from the
: beginning of left inside \verbatim.
: Another problem is that both verbatim and listings cannot
: automatically wrap the too-long lines, thus always make the output messy
: .

avatar
f*h
12


【在 z*****n 的大作中提到】
: I got one problem in verbatim environment: the table indents cannot be d
: isplayed and all lines starts from the
: beginning of left inside \verbatim.
: Another problem is that both verbatim and listings cannot
: automatically wrap the too-long lines, thus always make the output messy
: .

avatar
T*n
13

Do you mean "tab stops", i.e., what is usually associated with eight spaces?
In (La)TeX the ASCII TAB character is treated like a regular space, so it
is not expanded. You should take a look at using the fancyvrb package
http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/
and also read pages 160-161 in "The LaTeX Companion" 2nd edition.
You could put the verbatim environment within a quote environment to
have the verbatim text indented.
None of the verbatim environments will wrap li

【在 z*****n 的大作中提到】
: I got one problem in verbatim environment: the table indents cannot be d
: isplayed and all lines starts from the
: beginning of left inside \verbatim.
: Another problem is that both verbatim and listings cannot
: automatically wrap the too-long lines, thus always make the output messy
: .

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。