KTUGFaq

KTUG FAQ

α:
йȣ:
Let not the sands of time get in your lunch.
Memoir����&value=&value=Memoir����&value=?독후감&value=׸ › TeXLive&value=Karnes/Ǻ׸DHHangul/ȭ&value=ǥѱTeXȯƮLyX/�ѱ۾���&value=MiKTeXġ › SourceCodeListing
[]

Source Code Listing

1 Source Code Listing
1.1 Ϲ ȳ
1.2 ϰ ٹȣ ֱ
1.3 verbatim-like ҽڵ
1.3.1 verbatim ȯ
1.3.2 verbatim Ű ̿
1.3.3 sverb Ű
1.3.4 fancyvrb Ű ̿ ҽڵ
1.3.5 alltt Ű ̿ϴ
1.3.6 Moreverb Package ϴ
1.4 verbfile ̿ؼ ܺ file о ̱
1.4.1 sverb Ű \verbinput
1.4.2 verbatim Ű ܺ ó
1.4.3 moreverb Ű \verbatimtabinput
1.4.4 verbfile Ű
1.4.4.1 listing ̿ϸ Ͽ line number ߰ش.
1.4.4.2 verbfile ̿ϸ ̴ ״ Ѵ.
1.5 Programming Language Ưȭ
1.5.1 TeX c_pascal ϴ
1.5.2 Algorithmic Package ϴ
1.5.3 Program Package ϴ
1.5.4 Listings Package ϴ
1.6 Float Ͽ ڰ
1.6.1 floatstyle ̿ϴ
1.6.2 algorithm Ű
1.7 : ̻ ҽ Listing + TOC-like ÷ϱ
1.7.1 ī
1.7.2 TOC like ߰
1.7.3 environment
1.7.4
1.8 Ÿ
1.8.1 ҽڵ忡 ιȣ ߰ ƿƼ(python)
1.8.2 framed Ű ̿
1.8.3 ҽڵ带 LaTeX ڵ ȯϴ ƿƼ
1.8.4 C++2LaTeX S/W
1.9 LGrind Package ϴ
1.9.1 LGrind
1.9.2 ڵ
1.9.3
1.9.4 ڵȭ
1.10 Highlight
1.11 ҽ

[]

1.2 ϰ ٹȣ ֱ

KTUGOperate: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 verbatim-like ҽڵ

[]

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.3 sverb Ű

[]

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.5 alltt Ű ̿ϴ

\documentclass{article}
\usepackage{alltt}

\begin{document}
\begin{alltt}
void main(void)\{
    printf("Hello, world");
    printf("Hello,world");
    /*
      \emph{}
    */
\}
\end{alltt}
\end{document}
TeX ҽ Բ α׷ ҽ ϰ 찡 ִ. ̶ alltt package Ѵ.
  • α׷ { ϱ ؼ \{ ش.
  • \emph{} TeX ɾ ִ.

[]

1.3.6 Moreverb Package ϴ

from KTUGOperate:3173 (by Progress)

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} ִ 1 line (ٹȣ) մϴ. {3} ϸ ù 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 verbfile ̿ؼ ܺ file о ̱

[]

1.4.1 sverb Ű \verbinput


[]

1.4.2 verbatim Ű ܺ ó


[]

1.4.3 moreverb Ű \verbatimtabinput

\verbatimtabinputtab_size{input_file} ǻ ϸ鼭 ܺ ҷδ. \listinginput{input_file} ܺ ҷ̸鼭 ȣ ٿش.

[]

1.4.4 verbfile Ű

[]

1.4.4.1 listing ̿ϸ Ͽ line number ߰ش.

\usepackage{verbfile}
\listing{code/hello.c}

[]

1.4.4.2 verbfile ̿ϸ ̴ ״ Ѵ.

\usepackage{verbfile}
\verbfile{code/hello.c}

[]

1.5 Programming Language Ưȭ

[]

1.5.1 TeX c_pascal ϴ

c_pascal LaTeX Ű ʰ TeX def · ȴ.
  1. TEXMF\generic\c_pascal cap_c.tex (C ), cap_pascal(PASCAL) Ѵ.
  2. \BeginC --- \EndC ȿ ҽڵ带 ִ´.
  3. \InputC{filename} ̿Ѵ.
  4. \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}
c_pascal.jpg
[]

1.5.2 Algorithmic Package ϴ

[]

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}

prog.jpg
[]

1.5.4 Listings Package ϴ

KTUGOperate:8421 (by hoze)

\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 Float Ͽ ڰ

[]

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.6.2 algorithm Ű

[]

1.7 : ̻ ҽ Listing + TOC-like ÷ϱ

float ̿ϸ, ڵ listof ְ, ش. ׷ ̻ ҽ ϱ ؼ ȯ ־ Ѵ.
[]

1.7.1 ī

\newcounter{example}[section] % section  ڵ ī͸ 0  ش.
\setcounter{example}{1}
[]

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.7.4

\begin{slist}
\verbatiminput{biorhythm.rb}
\end{slist}
\ecaption{ȳϼ?}

߰ ֽñ ٶϴ. --smcho

[]

1.8 Ÿ

[]

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]http://www.ctan.org/tex-archive/support/lgrind/?action=/tex-archive/support/ ּҿ ҽڵ带 ٿε ׳ ʴ´. ҽڵ带 Win32 ȯ濡 ϸ ⿡ ٿε ȴ. Uploads:lgrind.zip
[]

1.9.1 LGrind

lgrind -i -lc -d lgrindef lgutil.c  > res.tex
ĽĮ ڵ -lpascal ִ. ڼ lgrind.pdf .

[]

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}

csource.jpg

[]

1.9.3

tex ϳ ξ Ѵ. ׷ \LGnuminterval=1 , ο ȣ ̴ 쿡 .

[]

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.10 Highlight

پ ׸ Ÿ ϴ ҽ ڵ . smcho ڿ ѱ(EUC-KR, UTF-8) ּ ó Ÿ Դ.

[]

1.11 ҽ

Ͽ . ̴ python ҽ hightlight ̿Ͽ LaTeX ̸ listofsource ȯ ̿Ͽ ó ̴. PDFHyperLink ̿ؼ pdf 󿡼 ٸ ҽ α׷ Ű ͵ ϴ. ̰쿡 python interpreter ־ Ѵ.


Contributors: smcho



^
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2007-02-18 04:44:39
Processing time 0.1224 sec