我希望我的文档的某些部分仅适用于给定的输出格式。例如,我有一个需要特殊 LaTeX 处理的图像,我想使用 \includegraphics 来处理它。但是对于 epub 版本,我想要标准行为。
Pandoc markdown 中是否有一种方法可以指定仅应在给定上下文中处理的部分(LaTex 与 epub)。模板有条件。我没有看到 Pandoc markdown 的功能。
或者有没有其他方法来处理这个用例?
这是文件预处理器filepp的解决方案。我们定义了一个由标志img(caption,path,options)替换或由\includegraphics标志代替的函数。请注意两件事:您需要在函数参数中转义逗号(请参阅第一个图的第三个参数);即使未指定一个参数,您也需要有两个未转义的逗号(请参阅下面的第二个示例图)。
测试文件
#bigfunc img(caption,path,options)
#if "out_fmt" eq "tex"
\begin{figure}
\caption{\label{caption} caption}
\includegraphics[options]{path}
\end{figure}
#else

#endif
#endbigfunc
Here is an image
img(Plot,Rplot.png,height=2\,width=2)
img(Plot,Rplot.png,)
Run Code Online (Sandbox Code Playgroud)
我们在 filepp 命令中指定输出格式并通过 pandoc 管道它:
filepp -m bigfunc.pm -D out_fmt=tex test.md | pandoc -o test.tex
filepp -m bigfunc.pm -D out_fmt=html test.md | pandoc -o test.html
Run Code Online (Sandbox Code Playgroud)
tex 输出:
Here is an image
\begin{figure}
\Plot{\label{Plot} Plot}
\includegraphics[height=2,width=2]{Rplot.png}
\end{figure}
\begin{figure}
\Plot{\label{Plot} Plot}
\includegraphics[]{Rplot.png}
\end{figure}
Run Code Online (Sandbox Code Playgroud)
html输出:
<p>Here is an image</p>
<div class="figure">
<img src="Rplot.png" alt="Plot" />
<p class="caption">Plot</p>
</div>
<div class="figure">
<img src="Rplot.png" alt="Plot" />
<p class="caption">Plot</p>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2136 次 |
| 最近记录: |