Mercurial > hg > Papers > 2020 > anatofuz-sigos
view paper/md2tex.pl @ 37:9e40a7a00a02
fix
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 06 May 2020 07:50:03 +0900 |
parents | 5dbe39f52406 |
children |
line wrap: on
line source
#!/usr/bin/env perl use strict; use warnings; use utf8; my $source_md = shift; my $target_tex = shift; open my $texFH, '>', $target_tex; { open my $fh, '<', 'md2tex/first.tex'; while (my $line = <$fh> ) { print $texFH $line; } close $fh; } open my $fh, '<', $source_md; my $in_codeblock = 0; while (my $line = <$fh>) { if ($line =~ /^```/) { $in_codeblock = !$in_codeblock; if (!$in_codeblock) { $line = '\end{lstlisting}' ."\n"; } if ($line =~ /``` lab:(.*),\s*cap:(.*)/) { $line = '\b'."egin{lstlisting}[frame=lrbt,label=$1,caption={$2}]\n"; } } if ($in_codeblock) { print $texFH $line; next; } if ($line =~/^#/) { $line =~ s/# (.*)/\\section{$1}/; } while ($line =~ /`([[:ascii:]]+?)`/g) { my $inlineCodeBlock = $1; $inlineCodeBlock =~ s/_/\\_/g; $line =~ s/`([[:ascii:]]+)`/\\texttt{$inlineCodeBlock}/; } if ($line =~ /!\[lab:(.*),\s*cap:(.*)\]\((.*)\)/) { $line = <<"EOF"; \\begin{figure}[tb] \\begin{center} \\includegraphics[width=80mm]{$3} \\end{center} \\caption{$2} \\label{$1} \\end{figure} EOF } if ($line =~ /^\[lab:(.*),\s*cap:(.*)\]\((.*)\)/) { $line = '\l' ."stinputlisting[label=$1, caption={$2}]{$3}\n"; } print $texFH $line; } close $fh; print $texFH <<'EOF'; \nocite{*} \bibliographystyle{ipsjunsrt} \bibliography{anatofuz-bib} \end{document} EOF close $texFH;