Pandoc跳过乳胶环境 [英] pandoc skip latex environment
问题描述
我主要用LaTeX写作,但是一些合著者更喜欢MS Word.为了方便他们的工作,我想将 .tex
文件(或 .pdf
)转换为 .docx
.格式不一定是完美的,但所有文本,方程式,图形等都应完全可读.
I'm writing mainly in LaTeX, but some co-authors prefer MS Word. To facilitate their work a bit, I would like to convert the .tex
file (or the .pdf
) to a .docx
. The formatting does not need to be perfect, but all of the text, equations, figures etc should be perfectly readable.
我目前正在考虑提取 .tex
文档,替换所有必需的内容,然后让Pandoc做到这神奇.为此,我最好将添加的内容实现为Pandoc过滤器.例如,我的 tikz
图片将使用Pandoc随附的 tikz.py
过滤器转换为 png
.我用这种方法面临的问题是Pandoc在从 tex
转换为其内部语言时尝试解释 tikz
环境,并且过滤器将此内部语言作为输入.结果是 tikz
代码丢失了.有没有办法告诉Pandoc保留任何 tikzpicture
环境?
I'm currently thinking to take the .tex
document, replace all the essential stuff and then let Pandoc do it's magic. For this I would preferably implement my additions as a Pandoc filter. E.g., my tikz
pictures would be converted to png
using the tikz.py
filter provided with Pandoc. The problem I'm facing with this approach is that Pandoc tries to interpret the tikz
environment upon conversion from tex
into it's internal language and the filters take this internal language as an input. The result is that the tikz
code is lost. Is there a way to tell Pandoc to leave any tikzpicture
environments alone?
请参阅下面的MWE:
MWE.tex内容:
MWE.tex contents:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (2,2);
\end{tikzpicture}
\end{document}
pandoc -t本机MWE.tex
[Para [Str "(0,0)",Space,Str "\8211",Space,Str "(2,2);"]]
\ draw
命令已完全消失.
推荐答案
我发现pandoc不会跳过封装在 \ iffalse
... \ fi
中的代码,因此您可以这样重新定义tikpicture环境(或您可能喜欢的任何其他方式):
I found that pandoc does not skip code encapsulated in \iffalse
... \fi
, so you can redefine the tikpicture environment as such (or in any other way you might like):
\documentclass{article}
\usepackage{tikz}
\iffalse
\renewenvironment{tikzpicture}%
{\par---start tikzpicture---\\}%
{\\---end tikzpicture---\par}
\renewcommand{\node}{node:}
\fi
\begin{document}
\begin{tikzpicture}
\node {foo};
\end{tikzpicture}
\end{document}
对于pandoc 2.5,这将导致docx文件包含:
With pandoc 2.5 this results in a docx file containing:
—start tikzpicture—
node:foo;
—end tikzpicture—
这感觉很不对劲,我希望我知道更好的方法.
This feels very wrong, and I wish I knew a nicer way.
这篇关于Pandoc跳过乳胶环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!