KTUGFaq
KTUG FAQ
With clothes the new are best, with friends the old are best.
占쏙옙占쏙옙占쏙옙占쏙옙占 › KTSWorkshop/2007/Photo2 › Wiki › LyX/�ѱ۾���&value=MacOSġϱ › 트占쏙옙타占쌉글꼴삼옙占쏙옙歐占 › PerlTeX
r1.8
@@ -1,8 +1,17 @@
'''PerlTeX'''
LaTeX ũθ ڵ ۼ ֵ ִ Ű.
* CTAN:macros/latex/contrib/perltex/
----
[[TableOfContents]]
== Ұ ==Perl ڵ带 LaTeX ũθ Դ ִ Ű̴. Perl ũΰ LaTeX ũη Ǵ ̴. ̷ν LaTeX ɷ° Perl α ɷ ְ ȴ.
== ==
ں `\usepackage{perltex}` Ѵ. `\perlnewcommand`, `\perlrenewcommand`, `\perlnewenvironment`, `\perlrenewenvironment` װ ̿ ִ.
@@ -49,12 +58,12 @@
== 2: DB List Plot ==
DB(MySQL) Ǿ ִ ġ Perl Ͽ ̸ PSTricks
̿Ͽ List plot ̴. ⼭
츮
List plot ü հ ִ밪,
ȴ.
=== DB
ϱ
۾ ===
ֵ DB Է ̱ ϰڴ.ϴ, localhost MySQL ġ Ǿ ִٰ ϰ,
1. DB
@@ -85,4 +94,187 @@
mysql> INSERT INTO perfdata (num,value) VALUES(10, 8.18);}}}
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
}}}
=== 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
ü Ͽ ϴ ٶϴ.
=== ===
{{{
$ perltex --nosafe drawgraph.tex
$ dvips -E drawgraph.dvi -o drawgraph.eps
}}}
--nosafe ɼ perltexü ִ ȱ
µ ⺻ ϰ ִµ, ⼭ ̸
ϵ ϴ ɼ̴.
Uploads:drawgraph.png
%%% ټ ϴٸ, perlTeX
%%% е鿡 ̳ Ǽ̱⸦ ٶϴ.
˼
%%% 2004.12.4 μ
DeleteMe. մϴ.
!!! '''
:) --[Karnes]
== ==
ȳϽʴϱ? 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]
== (μ) ==
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]
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.pl --latex=lambda --nosafe test.tex
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
ü Ͽ ϴ ٶϴ.
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