KTUGFaq
KTUG FAQ
You will be awarded a medal for disregarding safety in saving someone.
lshort-kr/Compile&value=ǥѱTeXȯƮ › 占쏙옙호占쏙옙占쏙옙&value=LaTeX/FindPage › Karnes-PrivateTmpPage&value=TeX › DVIPDFMx › FPfigure › SourceCodeListing
Source Code Listing ¶
1.2.1 verbatim ȯ ¶
verbatim ȯ ̿մϴ.
\begin{verbatim} for (int i = 0; i < 10; i++) { ... } \end{verbatim}
1.2.2 verbatim Ű ̿ ¶
\usepackage{verbatim} \verbatiminput{alltttest.tex}
verbatim Ű ̿ϴ ϴ.
- verbatim environment ϴ° memory overflow Ͼ ִٰ մϴ. ذմϴ.
- comment ȯ ̿ؼ TeX commenting ֽϴ.
- \verbatiminput մϴ.
1.2.4 fancyvrb Ű ̿ ҽڵ ¶
listings Ű ּ ѱ ̻ϰ ǥմϴ. fancyvrb Ű ּ ѱ ǥϴµ ϴ. Դٰ ۲ ϰ ȣ ֽϴ.
\documentclass[a4paper,12pt]{article}
\usepackage{hangul}
\usepackage{fancyvrb}
\title{fancyvrb Ű Ʈ}
\author{}
\date{\today}
\begin{document}
\maketitle
̰ ƮԴϴ.
\begin{Verbatim}
[fontfamily=cmtt,frame=single,baselinestretch=1,fontsize=\footnotesize,numbers=left]
#include <stdio.h>
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.2.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.3.3 moreverb Ű \verbatimtabinput ¶
\verbatimtabinputtab_size{input_file} ǻ ϸ鼭 ܺ ҷδ.
\listinginput{input_file} ܺ ҷ̸鼭 ȣ ٿش.
1.4.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.4.2 Algorithmic Package ϴ ¶
\documentclass{article} \usepackage{algorithmic} \begin{document} \begin{algorithmic} %EndExpansion \REQUIRE$n\geq 0$ \ENSURE$y=x^{n}$ \STATE$y\Leftarrow 1$ \STATE$X\Leftarrow x$ \STATE$N\Leftarrow n$ \WHILE{$N \neq 0$} \IF{$N$ is even} \STATE$X\Leftarrow X\times X$ \STATE$N\Leftarrow N/2$ \ELSE[$N$ is odd] \STATE$y\Leftarrow y\times X$ \STATE$N\Leftarrow N-1$ \ENDIF \ENDWHILE \end{algorithmic}% %EndExpansion \end{document}
1.4.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.4.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 ȿ ν Ϻ ذ ʴ. , ּ(/* ... */) 쿡 ѱ ̻ϰ µ ִ.
\begin{lstlisting}[escapeinside=`'] #include <stdio.h> int main(int argc, char *argv[]) { //`ο 带 ' printf("Hello, world\n"); return 0; } \end{lstlisting}Ǵ
\begin{lstlisting}[mathescape=true] #include <stdio.h> int main(int argc, char *argv[]) { //$\mbox{ο 带 }$ printf("Hello, world\n"); return 0; } \end{lstlisting}
1.5.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.6.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.6.3 environment ¶
\newenvironment{slist}{\noindent\rule{\textwidth}{1pt}\begin{list}{}{}\item[]} {\end{list}\noindent\rule{\textwidth}{1pt} \stepcounter{example}}
1.7.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.7.3 framed Ű ̿ ¶
framed Ű ̿ϸ ҽ θ ִ. ҽڵ尡 1 Ѿ Ѵ.
\begin{framed} \verbatiminput{framed.sty} \end{framed}
1.8 LGrind Package ϴ ¶
http://www.ctan.org/tex-archive/support/lgrind/?action=/tex-archive/support/
ּҿ ҽڵ带 ٿε ׳ ʴ´. ҽڵ带 Win32 ȯ濡 ϸ ٿε ȴ.
lgrind.zip
1.8.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.8.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.10 ҽ ¶
Ͽ .
̴ python ҽ hightlight ̿Ͽ LaTeX ̸ listofsource ȯ ̿Ͽ
ó ̴. PDFHyperLink ̿ؼ pdf ٸ ҽ α Ű ͵ ϴ.
̰쿡 python interpreter ־ Ѵ.
Contributors: smcho