我主要是用LaTeX写的,但一些合著者更喜欢MS Word。为了方便他们的工作,我想将.tex文件(或.pdf)转换为.docx。格式不需要是完美的,但所有的文本,公式,数字等应该是完美的可读性。
我目前正在考虑采用.tex文档,替换所有必要的东西,然后让Pandoc来施展它的魔力。为此,我最好将添加的内容实现为Pandoc过滤器。例如,我的tikz图片将使用随Pandoc提供的tikz.py过滤器转换为png。我使用这种方法面临的问题是,Pandoc试图在从tex转换为其内部语言时解释tikz环境,而过滤器将此内部语言作为输入。结果是tikz代码丢失。有没有办法告诉Pandoc不要去管任何tikzpicture环境?
编辑:参见下面的MWE:
MWE.tex内容:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (2,2);
\end{tikzpicture}
\end{document}pandoc -t native MWE.tex的输出
[Para [Str "(0,0)",Space,Str "\8211",Space,Str "(2,2);"]]如您所见,\draw命令已经完全消失了。
发布于 2020-09-21 06:49:35
我发现pandoc不会跳过\iffalse ... \fi中封装的代码,所以你可以这样重新定义tikpicture环境(或者以你喜欢的任何其他方式):
\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文件,其中包含:
—start tikzpicture—
node:foo;
—end tikzpicture—https://stackoverflow.com/questions/42906254
复制相似问题