KTUGFaq
KTUG FAQ
Karnes/2007-10&value=PDF › MiKTeX-KTUG&value=DHUcs/ȭ › Beamer/HLaTeX&value=ۼý › Karnes/2011-08&value= › 占쏙옙占쏙옙占 › SourceCodeListing
Source Code Listing ¶
1.2 ϰ ٹȣ ֱ ¶
20535
\usepackage{fancyvrb} \begin{Verbatim}[fontfamily=cmtt,frame=single,baselinestretch=1,fontsize= \footnotesize,numbers=left] ... \end{Verbatim}
Ȥ
\usepackage{moreverb} ... \begin{listing}{1} [page 1 0 0 0 0 0 0 0 0 0] fnt: cmr10 at 50pt set: 'Hello, World!' \end{listing} ...
\begin{listing}{num} num ۹ȣ Ÿ \begin{listing}{num}
\let\listinglabelsize\footnotesize ũ⸦ ִ.
1.3.1 verbatim ȯ ¶
verbatim ȯ ̿մϴ.
\begin{verbatim} for (int i = 0; i < 10; i++) { ... } \end{verbatim}
1.3.2 verbatim Ű ̿ ¶
\usepackage{verbatim} \verbatiminput{alltttest.tex}
verbatim Ű ̿ϴ ϴ.
- verbatim environment ϴ° memory overflow Ͼ ִٰ մϴ. ذմϴ.
- comment ȯ ̿ؼ TeX commenting ֽϴ.
- \verbatiminput մϴ.
1.3.4 fancyvrb Ű ̿ ҽڵ ¶
listings Ű ּ ѱ ̻ϰ ǥմϴ. fancyvrb Ű ּ ѱ ǥϴµ ϴ. Դٰ ۲ ϰ ȣ ֽϴ.
\documentclass{article} \usepackage{hangul} \usepackage{fancyvrb} \title{fancyvrb Ű Ʈ} \begin{document} ̰ ƮԴϴ. \begin{Verbatim} [fontfamily=cmtt,frame=single,baselinestretch=1,fontsize=\footnotesize,numbers=left] int main(int argc, char *argv[]) { //ѱ ּ1 /* ѱּ2 */ printf("ο \n\n\n"); printf("Hello, world\n"); return 0; } \end{Verbatim} \end{document}
ɼ ȴٸ \DefineVerbatimEnvironment ֽϴ.
\DefineVerbatimEnvironment {source}{Verbatim} {frame=single, baselinestretch=1, fontsize=\footnotesize, numbers=left} \begin{source} void hello { printf("hello world"); } \end{source}
1.3.6 Moreverb Package ϴ ¶
moreverb Ű ȯ մϴ. α ʿ ִ .
\begin{listing}[1]{1} \begin{equation*} \begin{CD} A \cap B @>j>\mbox{\small projection}>B \\ @V i V \mbox{\small injection} V @VVgV \\ A @<f<k< A\cup B \end{CD} \end{equation*} \end{listing}
⼭ \begin{listing}[1]{1} մϴ.
[1] ִ 1 ȣ Ű line ڸ ǹմϴ. 1 1ٸ ȣ .
[2] ° ٸ ȣ ٽϴ.
ִ 1 line (ٹȣ) մϴ. ϸ ù line ȣ 3 մϴ.
ϴ.
\begin{listing}[2]{3} \begin{equation*} \begin{CD} A \cap B @>j>\mbox{\small projection}>B \\ @V i V \mbox{\small injection} V @VVgV \\ A @<f<k< A\cup B \end{CD} \end{equation*} \end{listing}
ϰ \begin{listing} ~~ \end{listing} ȿմϴ.
1.4.3 moreverb Ű \verbatimtabinput ¶
\verbatimtabinputtab_size{input_file} ǻ ϸ鼭 ܺ ҷδ.
\listinginput{input_file} ܺ ҷ̸鼭 ȣ ٿش.
1.5.1 TeX c_pascal ϴ ¶
c_pascal LaTeX Ű ʰ TeX def · ȴ.
- TEXMF\generic\c_pascal cap_c.tex (C ), cap_pascal(PASCAL) Ѵ.
- \BeginC --- \EndC ȿ ҽڵ带 ִ´.
- \InputC{filename} ̿Ѵ.
- \font\tenrm=cmtt10 ߰Ѵ.
\documentclass{article} \font\tenrm=cmtt10 \input cap_c \begin{document} {\Large InputC example}\\ \InputC{./hello.c} \\ {\Large BeginC/EndC example}\\ \BeginC // this is a short demo program /* both kinds of comment are recognised */ // some compiler directives #pragma hdrfile "hello.sym" #include <stdio.h> #include <sys/stat.h> #pragma hdrstop // words not recognised as keywords are considered // to be identifiers and are typeset in italic void main() { int n; hello(0x1C); silly_funct(); } \EndC \end{document}
1.5.3 Program Package ϴ ¶
\documentclass{article} \usepackage{program} \begin{document} \begin{programbox} \mbox{A fast exponential procedure:} \BEGIN \FOR i := 1 \TO 10 \STEP 1 \DO |expt|(2,i); |newline| \OD \WHERE \rcomment{A comment here} \PROC |expt|(x,n) \BODY z := 1; \DO \IF n = 0 \THEN \EXIT \FI; \DO \IF |odd|(n) \THEN \EXIT \FI; n := n/2; x := x*x; \OD; n := n-1; z := z*x \OD; |print|(z) \ENDPROC \END \end{programbox} \end{document}
1.5.4 Listings Package ϴ ¶
\documentclass{article} \usepackage{listings} \begin{document} \lstset{numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt} \begin{lstlisting} fileviewer(Dir) :- new(F, frame('File Viewer')), send(F, append(new(B, browser))), send(new(D, dialog), below(B)), send(D, append(button(view, message(@prolog, view, B?selection?key)))), send(D, append(button(quit, message(F, destroy)))), send(B, members(directory(Dir)?files)), send(F, open). view(F) :- send(new(V, view(F)), open), send(V, load(F)). \end{lstlisting} \end{document}
Listings Ű ҽ ڵ忡 ѱ ̸ ǥ Ѵ. ȿ ǥϷ ѱ κ escape ȿ ν Ϻ ذ ִ. escape ۰ Ÿ ڴ listingϷ ϴ ڷ ʴ ߿ ̴. tilde ڸ escape ϱ Ѵٸ
ƽ ѱ ̷ Ͽ ó ִ .
\begin{lstlisting}[escapeinside=~~] #include <stdio.h> int main(int argc, char *argv[]) { //~ο 带 ~ /*~ ּ 쿡 ະ~ ~escape ش.~ */ printf("Hello, world\n"); printf("~ȳϼ~\n"); return 0; } \end{lstlisting}
1.6.1 floatstyle ̿ϴ ¶
\floatstyle{ruled} \newfloat{Program}{thp}{lop}[section] \listof{Program}{Program Listing} \begin{Program} \listing{png2jpgs.py} \caption{The Program} \end{Program}
The LaTeX Companion p.148 .
1.7.2 TOC like ߰ ¶
\makeatletter \newcommand{\listofexamples}{\@starttoc{xmp}} \newcommand{\ecaption}[1]{\addcontentsline{xmp}{example}{#1} \begin{centering} \bf Example \thesection .\theexample : #1 \\[1cm] \end{centering} } \newcommand{\l@example}[2]{\par\noindent#1 \dotfill {\itshape #2}} \makeatother
1.7.3 environment ¶
\newenvironment{slist}{\noindent\rule{\textwidth}{1pt}\begin{list}{}{}\item[]} {\end{list}\noindent\rule{\textwidth}{1pt} \stepcounter{example}}
1.8.1 ҽڵ忡 ιȣ ߰ ƿƼ(python) ¶
ڵ忡 ιȣ ߰ϴ Utility ̿ ֽϴ.
#!/usr/bin/python # -*- coding: UTF-8 -*- import string import os.path ADDED_SPLIT = "_lineadd" class AddLine: def __init__(self, fileName_): self._fileName = fileName_ # ̸ Ȯڸ и [name,ext] = os.path.splitext(fileName_) self._fileNameNew = name + ADDED_SPLIT + ext print self._fileNameNew def append(self): try: fp = open(self._fileName) fp2 = open(self._fileNameNew,"w") lines = fp.readlines(); # ϴ line strip Ѵ. count = 1 for line in lines: #line = string.rstrip(line) newline = "%4d: %s" % (count, line) count += 1 fp2.write(newline) except IOError: print "ERROR opening file" if __name__ == "__main__": line = AddLine("add_line.py") line.append()
1.8.2 framed Ű ̿ ¶
framed Ű ̿ϸ ҽ θ ִ. ҽڵ尡 1 Ѿ Ѵ.
\begin{framed} \verbatiminput{framed.sty} \end{framed}
1.9 LGrind Package ϴ ¶
http://www.ctan.org/tex-archive/support/lgrind/?action=/tex-archive/support/
ּҿ ҽڵ带 ٿε ׳ ʴ´. ҽڵ带 Win32 ȯ濡 ϸ ٿε ȴ.
lgrind.zip
1.9.2 ڵ ¶
\usepackage[leftno,lineno5]{lgrind} \usepackage{color} \LGnuminterval=1 % numbering interval \def\LGfsize{\small} % font size \def\BGfont{\ttfamily\color{cyan}} % default %\def\CMfont{\ttpfamily\bfseries\color{blue}} \def\KWfont{\ttfamily\color{blue}} % keyword \def\NOfont{\bfseries\color{red}} % Number \def\STfont{\ttfamily\color{green}} % String \def\TTfont{\ttfamily\upshape} \def\VRfont{\ttfamily\color{black}\small} % variable ... \lgrindfile{code/chap1/cradle.tex}
1.9.4 ڵȭ ¶
ġ path Ѵ.
lgrind -i -l%1 -d d:\prog\bin\lgrindef %2 > %3 rem ڵ ߰ϴ ߰Ͽ Ѵ. python d:\prog\bin\addblankline.py %3
ڵ ִ python α .
#!/usr/bin/python import sys def process(val_): try: f = open(val_,"r+") except IOError: print "Error! no such file" sys.exit() f.seek(0,2) f.write('\n') f.close() if __name__ == '__main__': try: val = sys.argv[1] except IndexError: print "Error! no argumnet" sys.exit() process(val)
.
lg pascal cradle.dpr cradle.tex
1.11 ҽ ¶
Ͽ .
̴ python ҽ hightlight ̿Ͽ LaTeX ̸ listofsource ȯ ̿Ͽ
ó ̴. PDFHyperLink ̿ؼ pdf ٸ ҽ α Ű ͵ ϴ.
̰쿡 python interpreter ־ Ѵ.
Contributors: smcho