【问题标题】:org-mode how to use custom command when exporting figuresorg-mode 导出图形时如何使用自定义命令
【发布时间】:2018-05-28 20:55:37
【问题描述】:

我正在使用我的大学提供的 TeX 样式,其中包含一个用于描述图形来源的特殊命令。由于某种未知的原因,他们决定将来源和标题放在不同的位置。所以我们有一个名为\figsource的附加命令。

我正在使用以下几行将图形插入到我的 org 文件中:

#+LABEL: fig:myfigure
#+CAPTION:My caption
[[file:img/fig1.pdf]]

导出到 Latex 中:

\begin{figure}[htbp]
\centering
\includegraphics[width=1\linewidth]{img/fig1.pdf}
\caption{My caption}  
\end{figure}

但是,要使用附加命令 \figsource 我需要类似:

\begin{figure}[htbp]
\centering
\includegraphics[width=1\linewidth]{img/fig1.pdf}
\caption{My caption}  
\figsource{Source: \cite{someone2015}}
\end{figure}

我如何从 org 获得这个?

我已经尝试过这个#+ATTR_LATEX: \figsource{Source: \cite{someone2015}},但没有成功。

【问题讨论】:

标签: emacs latex org-mode


【解决方案1】:

使用导出过滤器的方法

充实我的评论中的建议,这是一个“最终输出”过滤器的实现,它将额外的东西放在 `\end{figure}' 之前 - 不确定位置是否有所不同。但是请注意,额外的东西被假定为固定字符串:

* Code                                                        :noexport:

#+begin_src emacs-lisp
  (require 'ox)
  (defun my-custom-figsource (contents backend info)
    (when (eq backend 'latex)
      (replace-regexp-in-string "\\\\end{figure}"
                                "\\\\figsource{Source: \\\\cite{someone2015}}\n\\\\end{figure}" contents)))

  (add-to-list 'org-export-filter-final-output-functions #'my-custom-figsource)

#+end_src

* Figure

#+LABEL: fig:myfigure
#+CAPTION:My caption
[[file:img/fig1.png]]

其中导出到以下 TeX 片段:

\begin{figure}[htbp]
\centering
\includegraphics[width=.9\linewidth]{img/fig1.png}
\caption{\label{fig:org6271d58}
My caption}
\figsource{Source: \cite{someone2015}}
\end{figure}

处理\figsource 中的不同引用会更难,我不知道该怎么做。

使用#+ATTR_LATEX的方法

或者,您可以在#+ATTR_LATEX 中使用:caption 属性:

* Figure

#+LABEL: fig:myfigure
#+CAPTION:My caption
#+ATTR_LATEX: :caption \caption{\label{fig:myfigure}My caption}\figsource{Source: \cite{foo}}
[[file:img/fig1.png]]

设置标签有一些重复,但它是本地化的并且相当容易处理,并且该方法允许您轻松使用不同的源引用,但我不确定它如何与 org-mode 生成的标签交互.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 1970-01-01
    • 2014-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多