본문 바로가기

ktug

noweb한글 예제(oblivoir)

KTUG 의 예제(구구단)를 debian에서 실행한다.
약간 수정해야 했다 . 
knoweb의 경우 컴파일시 에러가 발생하여  noweb으로 컴파일하니 잘되었다.

% -*- mode: Noweb; noweb-code-mode: c-mode; c-indent-level: 4 -*-
\documentclass[a4paper,oldfontcommands]{oblivoir}
\usepackage{fapapersize}
\usefapapersize{*,*,30mm,*,30mm,*}

\usepackage{noweb}
\begin{document}

\title{구구단 예제를 noweb으로 한글과 함께 구현하기}
\author{지은이}
\date{\today}

\maketitle
\tableofcontents*

\section{구구단 만들기}
구구단을 해주는 프로그램을 작성해 보자.

@
가장 높은 레벨에서는 다음과 같이 처리할 수 있다.
<<nine.c>>=
<<헤더를 포함 하는 곳>>
<<engine>>
<<main>>
<<print>>
<<테스트>>
@

상태는 [[status]]로 표시가 가능하다.
<<헤더를 포함 하는 곳>>=
#include <stdio.h>
#include <assert.h>
@

<<engine>>=
/*
   DoxyGen string
*/
int engine(int x, int y)
{
  assert(x >= 0 && y >= 0);
  return (x * y);
}
@ %def engine

<<print>>=
/*
  Write down the result.
*/
int print(int x, int y, int z)
{
  printf("(%d) X (%d) = (%d)\n",x,y,z);
}
@

<<main>>=
/*
  Main Routine
*/
int main()
{
  int i, j;
  for (i = 1; i < 3; i++) {
    for (j = 1; j < 3; j++) {
      int z = engine(i,j);
      print(i,j,z);
    }
  }
}
@

<<테스트>>=
/*
  Test routine
*/
int test()
{
  printf("testme\n");
}
@

\section*{List of code chunks}
This list is generated automatically.
The numeral is that of the first definition of the chunk.
\nowebchunks
%\begin{multicols}{2}[
\section*{Index}
Here is a list of the identifiers used, and where they appear.
Underlined entries indicate the place of definition.
This index is generated automatically.
%]
\nowebindex
%\end{multicols}

%noweave -delay -filter btdefn -autodefs c -index nine.nw > nine.tex
\end{document}


컴파일 순서는 다음과 같다.
  • -filter btdefn 은 없어도 tex결과는 같은 듯 2008-06-21
  • autodefs c를 사용하지 않을 경우  nw source 화일에서 @ %def engine과 같이 적을 경우 결과 PDF의  code chunk아래 Defines, Uses가 출력되고 상호참조 및 마지막 Index에 그 결과가 나타난다.
  • oblivoir 로 하지 않고 article로 할 경우 pdflatex로 컴파일해도 hyperlink가 생성되지 않는다. wc.nw를 테스트 해보면 알수 있다.

#> noweave -delay -filter btdefn -autodefs c -index nine.nw > nine.tex
#> pdflatex nine
#> pdflatex nine

상호 참조,  chunk list, Index 모두 잘 생성 되었다.

Hacks
#> /usr/lib/noweb/markup gugu.nw |  /usr/lib/noweb/autodefs.c  |  /usr/lib/noweb/finduses -noquote |  /usr/lib/noweb/totex
#> noweave -v -delay autodefs c -index gugu.nw



결과 PDF 첨부