如何使用特定的前导将 Org 模式导出到 LaTeX? [英] How can I make Org-mode export to LaTeX with a specific preamble?

查看:14
本文介绍了如何使用特定的前导将 Org 模式导出到 LaTeX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行 C-c C-e l 将 Org 文件导出到 LaTeX 时,它会生成一个带有特定序言的文档.我希望它使用我选择的序言而不是这个特定的序言.假设我希望它使用以下序言:

When I do C-c C-e l to export an Org file to LaTeX it produces a document with a particular preamble. Instead of this particular preamble I would like it to use a preamble of my choice. Say that I want it to use the following preamble:

% 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.
immediatewrite18{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}% 	extsubscript and bugfixes for LaTeX
usepackage{microtype}
usepackage[strict=true]{csquotes}% Context-sensistive quotes. enquote "" enquote* ''. Use the integrated commands 	extcquote and lockcquote 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]}
}

我知道您可以在每个文件的基础上操作使用哪些包如手册中所述 但我希望此序言用于所有文件,除非 ) 另有说明.我想使用的序言包括以下内容:

I know that you can manipulate which packages are used on a per file basis as described in the manual but I want this preamble to be used for all files unless ) specify otherwise. The preamble I want to use includes the following:

  • 停用的包(例如上面的geometry)
  • RequirePackage 加载的包
  • input
  • immediatewrite18
  • usepackage 宏之后的注释
  • 一个 hypersetup 宏,用于识别 Org-mode 文件中的 #+TITLE#+AUTHOR
  • deactivated packages (such as geometry above)
  • packages loaded by RequirePackage
  • input macros
  • immediatewrite18 macros
  • comments after usepackage macros
  • a hypersetup macro that recognizes #+TITLE and #+AUTHOR from Org-mode files

推荐答案

停用的包(例如上面的geometry)

Org-mode 识别 LaTeX 代码块内的 LaTeX 语法,以及在内容中包含 LaTeX 文件时.(请参阅引用 LaTeX 代码.)

如上.

如上.

我相信这也应该如上所述,但是有一种替代方法可以解决这个问题.如果您使用其中的命令创建 sh 类型的源代码块,Org 将在导出时对其进行评估并产生所需的行为.但是,您必须启用 sh 作为 babel 语言类型才能使其工作.

I believe this should also be as above, however there is an alternate method of dealing with this. If you create a source code block of type sh with the command within it, Org will evaluate it on export and produce the desired behaviour. You have to enable sh as a babel language type for it to work however.

(require 'ob-shell)

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

You can also include sh as one of the languages loaded by babel by adding it to org-babel-load-languages

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

然后使用类似于以下的代码块来运行您的 ./vc

Then use a code block similar to the following to run your ./vc

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

只要它出现在您的 input{vc} 行之前,它就应该运行代码然后包含它.只需按照代码块

As long as this comes before your input{vc} line it should run the code and then include it. Simply follow the code-block with

#+LATEX: input{vc}

并且应该包含您的内容.

And your content should be included.

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

If the code is within a LaTeX block it should recognize it as LaTeX.

这必须包含在每个文档中,而不是单独的.以下将提供您对宏的期望.它不会在序言中,但最终会出现在文档的顶部,并且导出的行为确实符合预期(但是,如果通过来自 org 的 #+INCLUDE: 添加,它将不会按预期执行.

This will have to be included within each document rather than separate. The following will provide what you desire for your macros. It will not be within the preamble, however it will end up at the top of the document and the export does behave as expected (however it will not behave as expected if added through #+INCLUDE: from org.

#+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 导出类

如果您按照 worg 教程中的说明进行操作(请参阅 Org Latex 导出)您可以创建自己的导出类.如果您想完全控制序言中的包,您只需要:

Creating your own Latex export class

If you follow the instructions in the worg tutorials (See Org Latex Export) you can create your own export-class. If you want to have full control over the packages in the preamble you would simply need to:

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

您还可以在 \documentclass[NO-DEFAULT-PACKAGES] 行之间添加所需的包.另一种方法是使用以下方法将它们添加到文件本身:

You can also add in your desired packages between the \documentclass and [NO-DEFAULT-PACKAGES] lines. The alternative would be to add them to the file itself using:

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

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

As a third option, you can simply create a custom .sty file with the desired packages etc and include it as a single #+LATEX_HEADER:.

这篇关于如何使用特定的前导将 Org 模式导出到 LaTeX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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