我如何使Org-模式导出到LaTeX时有一个特定的前言?

问题描述 投票:21回答:4

当我做 C-c C-e l 导出一个Org文件到LaTeX时,它产生了一个带有特定序言的文档。我希望它使用我选择的前言来代替这个特定的前言。比如说,我想让它使用下面的序言。

% Don't forget to qpdf --linearize the final copy
\RequirePackage[l2tabu,orthodox]{nag}% Old habits die hard. All the same, there are commands, classes and packages which are outdated and superseded. nag provides routines to warn the user about the use of those.
\immediate\write18{sh ./vc}
\input{vc}% Version control macros (for \VCDateISO in \date) http://www.ctan.org/pkg/vc
\documentclass[a4paper,12pt]{article}% pt? doublepage?
%\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}% Latin Modern (derivate of Knuth's CM)
\usepackage{fixltx2e}% \textsubscript and bugfixes for LaTeX
\usepackage{microtype}
\usepackage[strict=true]{csquotes}% Context-sensistive quotes. \enquote "" \enquote* ''. Use the integrated commands \textcquote and \blockcquote rather than biblatex internal commands to get contex sensistive quotes for them too. s/babel/autostyle in new version.
\usepackage[bookmarks,pdfborder={0 0 0}]{hyperref}% links and pdfinfo. MUST BE LOADED LAST!

\hypersetup{% Setup for hyperref
pdftitle    = {[Title from #+TITLE]},
pdfauthor   = {[Author from #+AUTHOR]}
}

我知道你可以在每一个文件的基础上操纵使用哪些程序包 如手册所述 但我希望所有文件都使用这个前言,除非)另有规定。我想使用的前言包括以下内容。

  • 停用的软件包(如 geometry (以上)
  • 装入的包 RequirePackage
  • input
  • \immediate\write18
  • 后面的评论 usepackage
  • a hypersetup 宏,可识别 #+TITLE#+AUTHOR 从Org-mode文件
emacs latex org-mode
4个回答
16
投票

停用的软件包(如 geometry (以上)

Org模式可以识别LaTeX代码块中的LaTeX语法,也可以在内容中包含LaTeX文件。 (参见 引用LaTeX代码.)

装入的包 RequirePackage

同上。

输入宏

同上。

\immediate\write18

我相信也应该是如上所述,不过有一个替代的处理方法。 如果你创建一个类型为 sh 的命令,Org会在导出时评估它并产生所需的行为。 您必须启用 sh 作为巴别语言类型来工作。

(require 'ob-shell)

您也可以将 sh 作为babel加载的语言之一,将其添加到了 org-babel-load-languages

(acons 'sh 't org-babel-load-languages)

然后使用类似下面的代码块来运行你的.vc。

#+name: Test
#+begin_src sh :results output silent :exports results
  ./vc
#+end_src

只要这个代码块在您的 \input{vc} 行,它应该运行代码,然后将其包含在内。 只要在代码块后面加上

#+LATEX: \input{vc}

而且你的内容应该被包含在内。

usepackage宏后面的注释

如果代码在LaTeX块中,它应该将其识别为LaTeX。

A hypersetup 宏,从Org-mode文件中识别#+TITLE和#+AUTHOR。

这必须包含在每个文件中,而不是单独的。 下面的内容将为你的宏提供你想要的东西。 它将不在前言中,但是它将会被放在文档的顶部,而且导出的结果也会和预期的一样(但是如果它是通过 #+INCLUDE: 从org.Latex导出类

#+begin_latex
  \hypersetup{% Setup for hyperref
  pdftitle    = {{{{TITLE}}}}, %Org macro to take from #+TITLE
  pdfauthor   = {{{{AUTHOR}}}} %Org macro to take from #+AUTHOR
  }
#+end_latex

创建你自己的Latex导出类

如果你按照wormg教程中的说明(见 乳胶出口组织)你可以创建自己的导出类。 如果你想完全控制序言中的包,你只需要。

(add-to-list 'org-export-latex-classes
             '("<CLASS NAME>"
               "\\documentclass{article}
               [NO-DEFAULT-PACKAGES]
               [NO-PACKAGES]"
               <insert desired sectioning configuration>))

你也可以在你想要的包之间加入 \\documentclass[NO-DEFAULT-PACKAGES] 行。 另一种方法是将它们添加到文件本身,使用。

#+LATEX_CLASS: <CLASS NAME>
#+LATEX_HEADER: \usepackage{package}
...

作为第三种选择,你可以简单地创建一个自定义的.sty文件,包含所需的包等,然后将其作为一个单一的... #+LATEX_HEADER:.


4
投票

这并不能回答你的问题,但它确实允许你做你想做的事情。

(defun headless-latex ()
  "exports to a .tex file without any preamble"
  (interactive)
  (org-export-as-latex 3 nil nil nil t nil)
)

这个函数可以导出你的ORG-模式文件的内容。毫无预兆. 然后你可以 \input 到一个文件中,加上你想要的序言。进一步阅读。


1
投票

我使用不同的方法来完成事情。

定义一个类(我把它叫做 每文件类 因为一些奇怪的原因。你可以叫它别的名字)。) 把这段代码放在你的 .emacs :

;; per-file-class with minimal packages
(unless (find "per-file-class" org-export-latex-classes :key 'car
              :test 'equal)
  (add-to-list 'org-export-latex-classes
               '("per-file-class"
                 "\\documentclass{article}
                [NO-DEFAULT-PACKAGES]
                [EXTRA]"
                 ("\\section{%s}" . "\\section*{%s}")
                 ("\\subsection{%s}" . "\\subsection*{%s}")
                 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                 ("\\paragraph{%s}" . "\\paragraph*{%s}")
                 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))

在你的org文件中使用这个类。

#+LaTeX_CLASS: per-file-class。

#+LaTeX_CLASS_OPTIONS: [10pt, a4paper]


0
投票

我不允许评论(名声不好还是什么;-)),所以我发一个答案。之前的回答中有一段非常好的无头导出函数的代码。那段代码需要更新,以适应以后版本的org:

(defun headless-latex ()
  "exports to a .tex file without any preamble"
  (interactive)
  (org-latex-export-as-latex nil nil nil t nil)
  )
© www.soinside.com 2019 - 2024. All rights reserved.