Mercurial > hg > Papers > 2020 > anatofuz-sigos
annotate paper/md2tex.pl @ 53:f68cad98da69
add slide
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 May 2020 18:36:10 +0900 |
parents | 9e40a7a00a02 |
children |
rev | line source |
---|---|
7 | 1 #!/usr/bin/env perl |
2 use strict; | |
3 use warnings; | |
10 | 4 use utf8; |
5 | |
6 my $source_md = shift; | |
7 my $target_tex = shift; | |
8 | |
9 open my $texFH, '>', $target_tex; | |
7 | 10 |
11 { | |
12 open my $fh, '<', 'md2tex/first.tex'; | |
13 while (my $line = <$fh> ) { | |
10 | 14 print $texFH $line; |
7 | 15 } |
16 close $fh; | |
17 } | |
18 | |
10 | 19 open my $fh, '<', $source_md; |
14 | 20 |
21 my $in_codeblock = 0; | |
22 | |
7 | 23 while (my $line = <$fh>) { |
18 | 24 if ($line =~ /^```/) { |
14 | 25 $in_codeblock = !$in_codeblock; |
26 if (!$in_codeblock) { | |
27 $line = '\end{lstlisting}' ."\n"; | |
28 } | |
24 | 29 if ($line =~ /``` lab:(.*),\s*cap:(.*)/) { |
14 | 30 $line = '\b'."egin{lstlisting}[frame=lrbt,label=$1,caption={$2}]\n"; |
31 } | |
32 } | |
33 | |
18 | 34 if ($in_codeblock) { |
35 print $texFH $line; | |
36 next; | |
37 } | |
38 | |
39 if ($line =~/^#/) { | |
40 $line =~ s/# (.*)/\\section{$1}/; | |
41 } | |
42 | |
37 | 43 while ($line =~ /`([[:ascii:]]+?)`/g) { |
19 | 44 my $inlineCodeBlock = $1; |
45 $inlineCodeBlock =~ s/_/\\_/g; | |
37 | 46 $line =~ s/`([[:ascii:]]+)`/\\texttt{$inlineCodeBlock}/; |
18 | 47 } |
48 | |
24 | 49 if ($line =~ /!\[lab:(.*),\s*cap:(.*)\]\((.*)\)/) { |
23 | 50 $line = <<"EOF"; |
51 \\begin{figure}[tb] | |
52 \\begin{center} | |
29
5dbe39f52406
add readsyscall_state
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
53 \\includegraphics[width=80mm]{$3} |
23 | 54 \\end{center} |
55 \\caption{$2} | |
56 \\label{$1} | |
57 \\end{figure} | |
58 EOF | |
59 } | |
60 | |
24 | 61 if ($line =~ /^\[lab:(.*),\s*cap:(.*)\]\((.*)\)/) { |
14 | 62 $line = '\l' ."stinputlisting[label=$1, caption={$2}]{$3}\n"; |
63 } | |
10 | 64 print $texFH $line; |
7 | 65 } |
66 close $fh; | |
67 | |
10 | 68 print $texFH <<'EOF'; |
7 | 69 |
70 \nocite{*} | |
71 \bibliographystyle{ipsjunsrt} | |
72 \bibliography{anatofuz-bib} | |
73 | |
74 | |
75 \end{document} | |
76 EOF | |
10 | 77 |
78 | |
79 close $texFH; |