Mercurial > hg > Papers > 2020 > anatofuz-sigos
view paper/md2tex.pl @ 23:2be09c284a2e
add meta-cg-dg.pdf
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 04 May 2020 14:25:42 +0900 |
parents | 13d8fe4cfc5c |
children | d2a1d3d75484 |
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 =~ /``` (.*),\s*(.*)/) { $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 =~ /`([\s\w_\-\\]+)`/g) { my $inlineCodeBlock = $1; $inlineCodeBlock =~ s/_/\\_/g; $line =~ s/`([\s\w_\-\\]+)`/\\texttt{$inlineCodeBlock}/; } if ($line =~ /!\[(.*),\s*(.*)\]\((.*)\)/) { $line = <<"EOF"; \\begin{figure}[tb] \\begin{center} \\includegraphics[width=70mm]{$3} \\end{center} \\caption{$2} \\label{$1} \\end{figure} EOF } if ($line =~ /^\[(.*),\s*(.*)\]\((.*)\)/) { $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;