Pandoc中带有列的幻灯片 [英] Slides with Columns in Pandoc

查看:77
本文介绍了Pandoc中带有列的幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Beamer幻灯片中并排放置代码和图像.

I would like to have code and an image side-by-side in a Beamer slide.

在LaTeX中,我将对列进行此操作.我想在列结构中使用markdown.

In LaTeX I would do this with columns. I would like to use markdown within the column structure.

\begin{columns}
\column{.5\textwidth}

~~~~~~~~Python
>>> some python code
~~~~~~~

\column{.5\textwidth}

![](A_generated_image.pdf)

\end{columns}

不幸的是Pandoc不会在\ begin {columns}和\ end {columns}语句中处理降价.有没有解决的办法?

Unfortunately Pandoc doesn't process the markdown within the \begin{columns} and \end{columns} statements. Is there a way around this?

  • 是否可以在嵌入式LaTeX中使用markdown?
  • 是否有一个纯粹的降价解决方案?

推荐答案

我希望仍然有价值.我在Python中制作了 Pandoc过滤器来轻松放置列,因此您可以通过以下方式编写演示文稿: /p>

I hope still valuable. I made a Pandoc filter in Python to put columns easily, so you can write your presentations in this way:

# Hello World

[columns]

[column=0.5]

~~~python
    if __name__ == "__main__":
        print "Hello World"
~~~

[column=0.5]

This is how a "Hello World" looks like in Python

[/columns]

过滤器会将每个标记转换为\ begin {columns}和\ column {.5 \ textwidth},因此,上面的文档将上交

that the filter will convert each markup to \begin{columns} and \column{.5\textwidth}, so, the document above will turn in

\begin{frame}[fragile]{Hello}

\begin{columns}

\column{0.5\textwidth}

\begin{Shaded}
\begin{Highlighting}[]
    \NormalTok{some python code}
\end{Highlighting}
\end{Shaded}

\column{0.5\textwidth}

Hello World

\end{columns}

\end{frame}

代码过滤器在这里

import pandocfilters as pf

def latex(s):
    return pf.RawBlock('latex', s)

def mk_columns(k, v, f, m):
    if k == "Para":
        value = pf.stringify(v)
        if value.startswith('[') and value.endswith(']'):
            content = value[1:-1]
            if content == "columns":
                return latex(r'\begin{columns}')
            elif content == "/columns":
                return latex(r'\end{columns}')
            elif content.startswith("column="):
                return latex(r'\column{%s\textwidth}' % content[7:])

if __name__ == "__main__":
    pf.toJSONFilter(mk_columns)

如果您从不使用pandoc过滤器,只需将过滤器保存为与columnfilter.py(或您想要的其他名称)相同的文档位置,然后运行

If you never use a pandoc filter, just save the filter to the same document location as columnfilter.py (or other name you want) and run

pandoc -t beamer --filter columnfilter.py yourDocument.mkd

享受吧!

这篇关于Pandoc中带有列的幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆