annotate paper/md2tex.pl @ 47:49940c327b4e

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