我最近正在阅读Laurent Rosenfeld 和 Allen B. Downey 合着的 Think Perl 6, 这是一本非常好的读物。
它的 .tex 文件在 github 中可用。
为此,我们必须批处理上面存储库中包含的所有 .tex 文件。为此,我们必须转换乳胶代码:
\begin{verbatim}
say 42 == 42; # True
say 42 == 42.0; # True
say 42 === 42; # True
say 42 === 42.0; # False
\end{verbatim}
\begin{verbatim}
$x eq $y # $x is string-wise equal to $y
$x ne $y # $x is string-wise not equal to $y
$x gt $y # $x is greater than $y (alphabetically after)
$x lt $y # $x is less than $y (alphabetically before)
$x ge $y # $x is greater than or equal to $y
$x le $y # $x is less than or equal to $y
$x eqv $y # $x is truly equivalent to $y
\end{verbatim}
到
\begin{minted}{perl6}
say 42 == 42; # True
say 42 == 42.0; # True
say 42 === 42; # True
say 42 === 42.0; # False
\end{minted}
\begin{minted}{perl6}
$x eq $y # $x is string-wise equal to $y
$x ne $y # $x is string-wise not equal to $y
$x gt $y # $x is greater than $y (alphabetically after)
$x lt $y # $x is less than $y (alphabetically before)
$x ge $y # $x is greater than or equal to $y
$x le $y # $x is less than or equal to $y
$x eqv $y # $x is truly equivalent to $y
\end{minted}
我想用 Perl 6 来完成这个。这是我计划做的。
THIS IS DUMMY CODE
# First I want to skim all the .tex files in the cloned repo (with git)
for dir("ThinkPerl6/book") ->$file {
say $file if $file~~/\.tex/;
}
# Read each .tex file and modify, replace `\begin{verbatim}` with `\begin{minted}{perl6}`
for "$file.tex".IO.lines -> $line {
substitute with "\begin{minted}{perl6}" if $line ~~/\\begin\{verbatim\}/;
}
# Read each .tex file and modify, replace `\end{verbatim}` with `\end{minted}`
for "$file.tex".IO.lines -> $line {
substitute with "\end{minted}" if $line ~~/\\end\{verbatim\}/;
}
我无法超越。有什么帮助吗?使用正则表达式会很有帮助。
最好的祝福,
苏曼