KTUGFaq
KTUG FAQ
FrontPage › PerlTeX
LaTeX ¸ÅÅ©·Î¸¦ ÆÞ ÄÚµå·Î ÀÛ¼ºÇÒ ¼ö ÀÖµµ·Ï ÇØ ÁÖ´Â ÆÐÅ°Áö.
[ÆíÁý]
2 »ç¿ë¹ý ¶
ÇÁ¸®¾Úºí¿¡ \usepackage{perltex}¶ó°í ¼±¾ðÇÑ´Ù. ÀÌÁ¦ \perlnewcommand, \perlrenewcommand, \perlnewenvironment, \perlrenewenvironmentÀÇ ³×°¡Áö ¸í·ÉÀ» ÀÌ¿ëÇÒ ¼ö ÀÖ´Ù.
¹®¼ÄÄÆÄÀÏÀº perltex.plÀ̶ó´Â ½ºÅ©¸³Æ®¸¦ »ç¿ëÇÑ´Ù. ¿É¼ÇÀº ´ÙÀ½°ú °°´Ù.
--latex=program ±âº»°ªÀÎ latex ´ë½Å ´Ù¸¥ ½ÇÇà¸í·É(¿¹:pdflatex)À» ÁÙ ¼ö ÀÖ´Ù. --nosafe ±âº»°ªÀ¸·Î À§ÇèÇÑ PerlÄÚµå(¿¹: ÆÄÀÏ»èÁ¦)°¡ ½ÇÇàµÇÁö ¾Êµµ·Ï µÇ¾î Àִµ¥ ÀÌ ¿É¼ÇÀº ¾ÈÀüÀåÄ¡¸¦ Ç®¾îÁØ´Ù. ¸ðµç Perl Äڵ尡 ±×´ë·Î ½ÇÇàµÈ´Ù. --permit=feature ƯÁ¤ PerlÄڵ常À» ¾ÈÀüÀåÄ¡·ÎºÎÅÍ ÇØÁ¦ÇÑ´Ù. ¿©·¯¹ø ¿É¼ÇÀ» ÁÙ ¼ö ÀÖ´Ù.
[ÆíÁý]
3 º¸±â1: ÇÑ±Û Sorting ¿¹Á¦ ¶
test.tex:
\documentclass[a4paper]{article} \usepackage{perltex} \usepackage{dhhangul} \perlnewcommand{\sortarg}[1]{join ',', sort split ',', $_[0]} \newcommand{\teststring}{ÇѱÛ,°¡³ª´Ù,¿ì¸®³ª¶ó,´ëÇѹα¹} \begin{document} \begin{center} \teststring\\ $\Downarrow$\\ \sortarg{\teststring} \end{center} \end{document}
PerlTeXÀº TeX ¸ÅÅ©·Î¸¦ ¸¸³ª¸é À̸¦ È®Àå(expand)ÇÑ ÈÄ Perl·Î ó¸®ÇÑ´Ù. È®ÀåÀ» ¸øÇÏ°Ô ÇÏ·Á¸é \noexpand¸¦ TeX ¸ÅÅ©·Î ¾Õ¿¡ ºÙÀÌ¸é µÈ´Ù.
ÄÄÆÄÀÏ:
$ perltex.pl --latex=lambda --nosafe test.tex
[ÆíÁý]
4 º¸±â2: DB¿Í ¿¬µ¿ÇÑ List Plot ±×¸®±â ¶
º» ¿¹Á¦´Â DB(MySQL)¿¡ ÀúÀåµÇ¾î ÀÖ´Â ¼öÄ¡ µ¥ÀÌÅ͸¦ Perl·Î ÃßÃâÇÏ¿© À̸¦ PSTricks¸¦
ÀÌ¿ëÇÏ¿© List plotÀ» ±×¸®´Â ¿¹Á¦ÀÌ´Ù. ¿©±â¼ ±¸ÇöÇÏ·Á´Â °ÍÀº List plot¿¡¼ Àüü Æò±Õ°ú ÃÖ´ë°ª,
À» perl·Î »êÃâÇÏ¿© À̸¦ ¹Ù·Î TeXÀ¸·Î Ãâ·ÂÇÏ´Â ±â´ÉÀ» ÁÖ´Â °ÍÀÌ´Ù.
¿©±â ¿¹Á¦´Â Linux¿¡¼ »ç¿ëÇÏ´Â °ÍÀ» °¡Á¤ÇÏ°í testÇÏ¿´À¸³ª Windows¿¡¼µµ »ç¿ë°¡´ÉÇϸ®¶ó
»ý°¢µÈ´Ù.
[ÆíÁý]
4.1 DB°ü·Ã »çÀü ÀÛ¾÷ ¶
º» ¿¹Á¦¸¦ µû¶ó ÇÒ ¼ö ÀÖµµ·Ï DB »ý¼º¿¡¼ µ¥ÀÌÅÍ ÀÔ·Â ±×¸®°í ÃßÃâ±îÁö¸¦ º¸À̱â·Î ÇÏ°Ú´Ù.
ÀÏ´Ü, localhost¿¡ MySQLÀÌ ¼³Ä¡ µÇ¾î ÀÖ´Ù°í °¡Á¤ÇÏ°í,
1. DB Á¢¼Ó ¹× À¯Àú »ý¼º
% mysql -h localhost -p -u root Enter password: ***** mysql> GRANT ALL ON perltexdb.* TO 'ptuser'@'localhost' IDENTIFIED BY 'ptpass'; Query OK, 0 rows affected (0.09 sec) mysql> CREATE DATABASE perltexdb; Query OK, 1 row affected (0.08 sec) mysql> quit2. Table »ý¼º ¹× µ¥ÀÌÅÍ ÀÔ·Â
% mysql -h localhost -p -u ptuser Enter password: ptpass mysql> USE perltexdb; mysql> CREATE TABLE perfdata (num INT, value FLOAT); mysql> INSERT INTO perfdata (num,value) VALUES(1, 10.21); mysql> INSERT INTO perfdata (num,value) VALUES(2, 20.22); mysql> INSERT INTO perfdata (num,value) VALUES(3, 30.23); mysql> INSERT INTO perfdata (num,value) VALUES(4, 40.24); mysql> INSERT INTO perfdata (num,value) VALUES(5, 50.25); mysql> INSERT INTO perfdata (num,value) VALUES(6, 52.24); mysql> INSERT INTO perfdata (num,value) VALUES(7, 30.23); mysql> INSERT INTO perfdata (num,value) VALUES(8, 20.22); mysql> INSERT INTO perfdata (num,value) VALUES(9, 10.21); mysql> INSERT INTO perfdata (num,value) VALUES(10, 8.18);
[ÆíÁý]
4.2 DB¿¡¼ µ¥ÀÌÅÍ °¡Á®¿À±â ¶
PerlÀÇ DBI moduleÀ» »ç¿ëÇÏ¿© PSTricks¸¦ ÅëÇØ Graph¸¦ ±×¸± ¶§
ÇÊ¿äÇÑ ÀÔ·Â data ÆÄÀÏÀ» »ý¼ºÇÑ´Ù.
connect.pl :
#! /usr/bin/perl -w # connect.pl - connect to the MySQL server use strict; use DBI; my $dsn = "DBI:mysql:host=localhost;database=perltexdb"; my $mysqldbh = DBI->connect ($dsn, "ptuser", "ptpass") or die "Cannot connect to server\n"; my $mysqlsth= $mysqldbh->prepare( "SELECT num, value FROM perfdata" ); open(DATAFH, ">perfdata.dat"); $mysqlsth->execute(); my $count = 0; while (my @val = $mysqlsth->fetchrow_array ()) { print DATAFH "$val[0]\t$val[1]\n"; ++$count; } $mysqlsth->finish(); print "$count rows were returned\n";Âü°í: ¿©±â¼ ³ë·ÃÇÑ µ¶ÀÚ´Â ¿Ö, ÀÌ¿Í °°Àº DB ¿¬°á code ¶ÇÇÑ perlTeX¿¡¼
±¸ÇöÇÏÁö ¾Ê¾ÒÀ»±îÇÏ´Â Àǹ®ÀÌ ÀÖÀ» °ÍÀÌ´Ù. »ç½Ç µÚ¿¡¼ º¸ÀÌ°ÚÁö¸¸
connect.pl°ú perlTeX code¸¦ µû·Î »ç¿ëÇÏ¸é °¢°¢ ½ÇÇàÇؾßÇÏ´Â ºÒÆí
ÇÔÀÌ ÀÖ´Â °ÍÀÌ »ç½ÇÀÌ´Ù. ÇÊÀÚµµ óÀ½¿¡´Â perlTeX ³»¿¡¼ connect.pl
°ú °°Àº code¸¦ Ãß°¡ÇÏ·Á ÇÏ¿´À¸³ª, DBI moduleÀÌ C·Î Â¥¿©Á® ÀÖ´Â
moduleÀÌ¶ó¼ ±×·±Áö, embeded perl error°¡ ¹ß»ýÇÏ¿´´Ù. ¾ÆÁ÷±îÁö
ÀÌ ¹®Á¦°¡ perlTeXÀÇ ÇÑ°èÀÎÁö, ¾Æ´Ï¸é ´Ù¸¥ ¹æ¹ýÀÌ ÀÖ´ÂÁö´Â ¾Ë ¼ö
¾øÀ¸³ª ÀÏ´Ü ¹®Á¦¸¦ ¿ìȸÇϸç ÇØ°áÇÏ´Â °ÍÀ¸·Î Á¤ÇÏ¿´´Ù.
-- ÃÖ±Ù¿¡ ³ª¿Â versionÀ¸·Î ½ÇÇàÇØ º¸´Ï, perltex.pl·Îµµ Á¤»óÀûÀ¸·Î perfdata.datÈÀÏÀº ³ª¿À´Â °ÍÀ» È®ÀÎÇÏ¿´½À´Ï´Ù. --synapse
connect.pl ½ÇÇà °ú °á°ú
$ perl connect.pl 10 rows were returned $ cat perfdata.dat 1 10.21 2 20.22 3 30.23 4 40.24 5 50.25 6 52.24 7 30.23 8 20.22 9 10.21 10 8.18
[ÆíÁý]
4.3 perlTeX¿Í PSTricks¸¦ ÀÌ¿ëÇÏ¿© list plot graph ÀÛ¼º ¶
¿©±â¼ óÀ½¿¡ ¸»ÇßµíÀÌ ´Ü¼øÈ÷ graph¸¸ ÀÛ¼ºÇÏ´Â °ÍÀÌ ¾Æ´Ï¶ó
ÁÖ¾îÁø µ¥ÀÌÅÍÀÇ ÃÖ´ë°ª, Æò±ÕÀ» ÇÔ²² Ãâ·ÂÇÏ´Â code¸¦
ÀÛ¼ºÇÏ´Â °ÍÀÌ ¸ñÀûÀÌ´Ù.
drawgraph.tex :
\documentclass[12pt]{report} \usepackage{pst-plot} \usepackage{perltex} \perlnewcommand{\findmax}[1]{ #! /usr/bin/perl -w use strict; open(PERFD, "<$_[0]"); my ($maxday,$maxval) = (0,0); while(<PERFD>) { my ($day, $val) = split /\s+/, $_; if ($maxday == 0){ ($maxday,$maxval) = ($day,$val); } if ($val > $maxval) { ($maxday,$maxval) = ($day,$val); } } $maxval= sprintf("%.2f",$maxval); my $returnstr="($maxday, $maxval)"; return "\\rput(2,-2.7){MAX: $returnstr}"; } \perlnewcommand{\findavg}[1]{ #! /usr/bin/perl -w use strict; open(PERFD, "<$_[0]"); my $numofdata=0; my $average=0; while(<PERFD>) { ++$numofdata; my ($day, $val) = split /\s+/, $_; $average += $val; } $average = $average / $numofdata; $average= sprintf("%.2f",$average); return "\\rput(7,-2.7){AVG: $average}"; } \begin{document} \pagestyle{empty} \newcommand{\DFILE}{./perfdata.dat} \readdata{\DATA}{./perfdata.dat} \psset{xunit=1,yunit=0.8} \begin{pspicture}(0,-2)(12,7) \psset{showpoints=true,dotsize=0.1,plotstyle=line,linewidth=1pt} \rput(0,7){Value} \rput(11.7,0){Num} \rput(5,-1.5){\bf{Example for perlTeX}} \listplot[plotstyle=line,yunit=0.08cm,dotscale=2,linecolor=green]{\DATA} \psaxes[dy=0.8cm,Dy=10,Dx=1]{->}(0,0)(11.10,6.5) \findmax{\DFILE} % <--- \rput(3,-2.7){MAX: ÃÖ´ë°ª} À» Ãâ·Â \findavg{\DFILE} % <--- \rput(7,-2.7){AVG: Æò±Õ°ª} À» Ãâ·Â \end{pspicture} \end{document}
À§ÀÇ code¸¦ ÅëÇØ perlTeXÀÇ ´ë·«ÀûÀÎ »ç¿ë¹ýÀ» ÀÍÈú ¼ö ÀÖ´Ù.
\perlnewcommand¶ó´Â perlTeXÀÇ macro Á¤ÀǸ¦ ÅëÇØ perl code¸¦ latex ÆÄÀÏ¿¡
³»Àå ½Ãų¼ö Àִµ¥, Ç×»ó Ãâ·ÂÀº return \rput(2,-2.7){MAX: $returnstr};
¿Í °°ÀÌ latex code·Î ÇÑ´Ù. Áï, perlÀÌ latex code¸¦ ¸¸µé¾î ÁÖ´Â °ÍÀÌ´Ù.
¿©±â¼ ÇÑ°¡Áö ÇÊÀÚ°¡ °æÇèÇÑ ¹Ù¸¦ ¿¹¸¦ µé¾î µ¡ºÙÀÌ°íÀÚ ÇÑ´Ù.
À§ÀÇ code¿¡¼ \findavg ÇÔ¼ö¿¡¼ÀÇ return °ªÀ» À§¿¡¼¿Í °°ÀÌ
return \rput(2,-2.7){AVG: $returnstr}; ·Î ÇÏÁö ¾Ê°í,
return $average; °ú °°ÀÌ °ª¸¸ ¹ÝȯÇÏ°Ô ÇÑ ÈÄ,
\findavg{\DFILE} ´ë½Å¿¡ \rput(3,-2.7){AVG: \findavg{\DFILE}}
°ú °°ÀÌ ÇÒ ¼öµµ ÀÖÀ» °ÍÀÌ´Ù. Å×½ºÆ® ÇÑ ¹Ù·Î´Â ÀÌ·¸°Ô Çصµ °°Àº
°á°ú¸¦ ¾òÀ» ¼ö ÀÖ¾ú´Ù. ±×·±µ¥, Á»´õ º¹ÀâÇÑ »óȲ¿¡¼ ÀÌ·¸°Ô
¼öÄ¡¸¸ perlTeX¸¦ ÅëÇØ Ãâ·ÂÇÏ°Ô¸é, stack overflow error ¸¦ ¹ß»ýÇÏ°Ô
µÇ´Â °æ¿ì°¡ ¹ß»ýÇÏ¿´´Ù. (±¸Ã¼ÀûÀ¸·Î ¿¹¸¦ µé¸é,
\psaxes[dy=0.8cm,Dy=10,Dx=1]{->}(0,0)(11.10,6.5) ¿¡¼ 0.8cmÀ̶ó´Â
°ªÀ» perlTeXÀÇ ³»ºÎ ¿¬»ê code¸¦ ÅëÇØ ¾ò¾îÁöµµ·Ï ÇÏ°íÀÚ ÇÒ ¶§,
±×·± °æÇèÀÌÀÖ´Ù.) µû¶ó¼ °á·ÐÀº, perlTeX¸¦ »ç¿ëÇÒ¶§´Â °¡±ÞÀûÀ̸é
¼öÄ¡ ÀϺκР¸¸ Ãâ·ÂÇÏ¿© latex code È ÇÏÁö ¸»°í, ´ÜÀ§ latex code
Àüü¸¦ À§ÀÇ ¿¹¿Í °°ÀÌ Ãâ·ÂÇÏ¿© ÇÏ´Â °ÍÀÌ ¹Ù¶÷Á÷ÇÏ´Ù.
[ÆíÁý]
4.4 °á°ú ¾ò¾î ³»±â ¶
$ perltex --nosafe drawgraph.tex $ dvips -E drawgraph.dvi -o drawgraph.eps
À§¿¡¼ --nosafe ¿É¼ÇÀº perltexÀÚü¿¡¼ °¡Áö°í ÀÖ´Â º¸¾È±â´ÉÀ¸·Î
ÆÄÀÏ ÀÔÃâ·ÂµîÀ¸·Î ±âº»ÀûÀ¸·Î Â÷´ÜÇÏ°í Àִµ¥, ¿©±â¼´Â À̸¦
Çã¿ëÇϵµ·Ï ÇÏ´Â ¿É¼ÇÀÌ´Ù.
Ãâ·Â °á°ú
%%% ´Ù¼Ò ºÎÁ·ÇÑ µíÇÑ ´À³¦ÀÌ µì´Ï´Ù¸¸, perlTeX¿¡ °ü½ÉÀÌ ÀÖÀ¸½Å
%%% ºÐµé¿¡°Ô Á¶±ÝÀ̳ª¸¶ µµ¿òÀÌ µÇ¼Ì±â¸¦ ¹Ù¶ø´Ï´Ù.
%%% 2004.12.4 ¿ÀÀμö
[ÆíÁý]
5 Áú¹® ¶
¾È³çÇϽʴϱî? perl·Î tex¸¦ ÇÒ ¼ö ÀÖ´Ù´Ï ¸Å¿ì ÁÁ¾Æº¸ÀÔ´Ï´Ù. Á¦°¡ ÀÏÀü¿¡ ktugÀÇ practical use¸¦ Á¤¸®ÇØ º¼·Á°í perl¸¦ ÀÌ¿ëÇؼ parctical useºÎºÐÀ» down¹Þ¾Æ º»ÀûÀÌ ÀÖ½À´Ï´Ù. ±×¶§´Â ÇÑÂü ´õ Çغ¸·Á°í Çߴµ¥, ±×¸¸ ½Ã°£°ú ´É·ÂÀÌ µþ·Á¼ ¸øÇÏ°í ¸»¾Ò½À´Ï´Ù. ±×·¸´Ù¸é, °¡·É ´ÙÀ½°ú °°Àº °Íµµ °¡´ÉÇÑÁö¿ä?
perl¸¦ ÀÌ¿ëÇؼ À§ÀÇ KtugWiki page¸¦ down¹Þ°í(title page¿¡¼ wikipage name¸¦ ¹Þ°í ³ÈÄ¿¡ °¢°¢ÀÇ Pagenameº°·Î À§ÀÇ ³»¿ëÀ» down¹Þ´Â´Ù) ³ÈÄ¿¡ ÀÌ ³»¿ëÀ» perl¸¦ ÀÌ¿ëÇؼ(wiki¹®¹ýÀ» tex·Î ¹Ù²Ù´Âµ¥ perl¸¦ ÀÌ¿ëÇØ¾ß ÇÒ °Í °°½À´Ï´Ù) tex·Î ¹Ù²Ü¼ö ÀÖÀ»±î¿ä? ¾îÂ¸é ±×³É perl·Î ´Ù ÇÒ ¼öµµ ÀÖÀ» ÀÏ °°À̵µ »ý°¢Àº µì´Ï´Ù¸¸......
±×·±´Ù°í Çؼ Á¦°¡ wikipage¸¦ down¹Þ¾Æ¼ ¾îÂî ÇØ º¸°Ú´Ù´Â ¸»Àº ¾Æ´Õ´Ï´Ù. ±×·¡µµ ¾ÕÀ¸·Î Á¡Á¡´õ wikipage°¡ ¸¹¾ÆÁö¸é, ¾ðÁ¦°¡´Â ´©±º°¡¿¡ ÀÇÇؼ ÀÌ·±ÇÑ ÀÏÀÌ µÇ¾îÁ®¾ß ÇÏÁö ¾ÊÀ»±î? »ý°¢Çؼ ±×³É Çѹø »ý°¢³ª´Âµ¥·Î Àû¾î º¸¾Ò½À´Ï´Ù. wikiµµ ÁÁÁö¸¸, ¾Æ¹«·¡µµ Á¦ ³ªÀÌ(?)¿¡´Â ±×³É Ã¥À¸·Î ÇÑ±Ç °¡Áö°í ÀÖ´Â °Íµµ ÁÁ½À´Ï´Ù.
¿©±â¿¡ ÀÌ·± ³»¿ëÀÌ ¾î¿ï¸®Áö ¾ÊÀ¸¸é Áö¿ì¼Åµµ °ü°è¾ø½À´Ï´Ù. --synapse
[ÆíÁý]
6 Áú¹®¿¡ ´ëÇÑ ÀúÀÇ »ý°¢(¿ÀÀμö) ¶
Àúµµ wiki¸¦ º¸¸é¼, TeXÀÇ ¹Ì·ÁÇÑ Ãâ·Â°ú ºñ±³ÇØ º¸¸é
¸¹ÀÌ °¡µ¶¼ºÀÌ ¶³¾îÁö´Â °ÍÀÌ »ç½ÇÀ̶ó synapse ´Ô°ú °°Àº »ý°¢À»
ÇÒ ¶§°¡ ÀÖ½À´Ï´Ù. À§¿Í °°ÀÌ ±¸ÇöÇÏ´Â °ÍÀº ÃæºÐÈ÷ °¡´ÉÇÑ
ÀÏÀ̶ó°í »ý°¢ÇÕ´Ï´Ù. perlÀÇ text processing ´É·ÂÀ¸·Î
ÃæºÐÇÒ °ÍÀ̶ó°í »ý°¢µÇ°í, tex source¸¦ web page·Î º¯È¯ÇÏ´Â
°ÍÀÌ ºñ½ÁÇÑ ¿¹Á¦¶ó°í »ý°¢µË´Ï´Ù. ±¸Ã¼Àû ±¸ÇöÀº Á»´õ »ý°¢ÇØ
ºÁ¾ß °ÚÁö¸¸, °¡´ÉÇϴٴµ¥ ¹«°Ô¸¦ µÎ°í ½Í½À´Ï´Ù.
%%% ¿ÀÀμö 2004.12.4
°¨»çÇÕ´Ï´Ù. ±×·±µ¥ ÀÌ¹Ì wiki¿¡¼´Â tex¹®¼¸¦ º¯È¯ÇÏ°í ÀÖ½À´Ï´Ù.(¿ÏÀüÇÑ º¯È¯Àº ¾Æ´Ï±¸¿ä) ¹°·Ð Á¦°¡ ½áº» wiki¶ó°í ÇغÁ¾ß wikix»ÓÀÌÁö¸¸¿ä.Á¦°¡ ¾ó¸¶Àü¿¡ Á¶Èñ´ë´ÔÀÇ µµ¿òÀ¸·Î wikiX¿¡¼ tex¹®¼¸¦ wiki·Î º¯È¯Çϱâ´Â Çß½À´Ï´Ù. ¹°·Ð ÀüÀûÀ¸·Î Á¶Èñ´ë´ÔÀÌ ´Ù ÇØ ÁÖ¼ÌÁö¸¸Àº¿ä?. ¹Ý´ë·Î wiki¿¡¼ tex·Î ¹ÝȯÇÏ´Â °Íµµ ±×¸® ¾î·ÁÁö´Â ¾ÊÀ» °Í °°Àºµ¥¿ä? ¾îÂ¸é ´õ ½¬¿ï¼öµµ ÀÖÀ»µí ½Í±â´Â ÇÕ´Ï´Ù. ±×³É »ý°¢¿¡ wiki¹®¹ýÀ̶ó°í ÇغÁ¾ß º°·Î µÇÁö ¾Ê±â ¶§¹®¿¡.... tex¹®¹ý¿¡ ºñÇϸé¿ä..... À̹ø ±âȸ¿¡ Á¶Èñ´ë´Ô²² Çѹø ¿©ÂÞ¾î º¼±î¿ä? ±×·±µ¥ ÀÌÀÏÀº ¾Æ¹«·¡µµ karnes´ÔÀÇ Çã°¡°¡ ÀÖ¾î¾ß ÇÏÁö ¾ÊÀ»±î »ý°¢ÇÕ´Ï´Ù. ±×·±µ¥ ¿ëµÎ»ç¹Ì°¡ µÇÁö ¾ÊÀ»±î? °ÆÁ¤¸¸ ¾Õ¼´Â±º¿ä.... --synapse