Mercurial > hg > Papers > 2020 > anatofuz-sigos
view paper/md2tex.pl @ 14:dff5f09c28c7
use listings
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 01 May 2020 13:07:45 +0900 |
parents | d43b107ad199 |
children | 875bf4bc5059 |
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 =~/^#/) { $line =~ s/# (.*)/\\section{$1}/; } 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 ($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;