English 中文(简体)
我怎么能够把Org-mode出口到有具体序言的LaTeX?
原标题:How can I make Org-mode export to LaTeX with a specific preamble?

当我做C-c C-e l,向LaTeX出口一个Org文档时,它就产生了一份带有特定序言的文件。 我不想使用我所选择的序言。 我想用以下序言:

% 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]}
}

我知道,你可以操纵每个档案上使用哪些包裹:手册》所述,但我希望这一序言用于所有档案,除非......)另有说明。 序言

  • 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
最佳回答

Deactivated packages (such as geometry above)

Org-mode承认LaTeX在LaTeX代码锁内,以及在将LaTeX文档列入内容时。 (见 Quoting LaTeX代码

Packages loaded by RequirePackage

见上文。

Input macros

见上文。

immediatewrite18 macros

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作为巴贝尔加载的语文之一列入<条码>。

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

然后使用类似于以下的法典,以管理你。

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

只要在您的<代码>输入-vc}上出现,就应当操作该代码,然后将其列入。 简单地沿用编码锁。

#+LATEX: input{vc}

你们的内容应当包含在内。

Comments after usepackage macros

如果该守则属于LaTeX集团,它应当承认它为LaTeX。

A hypersetup macro that recognizes #+TITLE and #+AUTHOR from Org-mode files.

这必须列入每个文件,而不是单独文件。 下面是你对你的宏观希望。 它将不在序言部分,但最终将在文件顶端,而且出口确实按预期进行(如果通过<代码>#+INCLUDE:从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

Creating your own Latex export class

如果你遵循Worg tutorials的指示(见Orgmurx Export),你可以创建自己的出口类别。 如果你想要完全控制序言中的一揽子计划,你就只需:

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

您还可以在<条码>/文件和<条码>之间添加<条码>。 另一种做法是,在档案中添加:

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

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:.

问题回答

这没有回答你的问题,但的确允许你做你想要做的事情。

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

这项职能出口贵组织网站的内容,没有序言部分<>。 然后,请将<条码>输入 进一步阅读:

我使用不同的方法做事:

界定一个类别(我称之为per-file-class,因为有些奇怪的原因。 你可以把它称作其他东西。 在您的<>中加入这一法典:

;; 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}"))))

Use this class in your org file :

# + LaTeX_CLASS: perfile-class

#+LaTeX_CLASS_OPTIONS: [10pt, a4paper]

I m not allowed to comment (bad reputation or something ;-)) so I will post an answer. A previous answer had a very nice snippet of code for a headless export function. That code needs updating for later versions of org:

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




相关问题
suppress additional braces in emacs electric mode

I started using ruby-electric-mode. I like it except that I am used to closing open brackets myself (the other pairing are still useful to me). How can I make emacs suppress additional brackets when ...

Setting up an emacs environment in windows?

I am currently constrained to a windows dev box and I want to migrate my projects from eclipse to emacs. What are some good references on setting up an emacs dev environment for windows? Anything ...

Emacs Setting which-function-mode

I would like to have which-function-mode on by default when I open up Emacs. I ve added the following lines to my .emacs file. (setq which-func-mode t) (setq which-function-mode t) When I open ...

Enabling go mode for emacs

I don t seem to be able to enable a go mode for emacs. C mode doesn t work without semicolons. The best I have found is the JavaScript mode by Karl Landstrom, since JavaScript also doesn t require ...

Custom Emacs key bindings are not working

The key bindings I ve defined in my .emacs file aren t working. Here s the file: ;init modes (menu-bar-mode 0) (tool-bar-mode 0) (cua-mode) (column-number-mode) (fset perl-mode cperl-mode) (cperl-...

eval during emacs lisp macro expansion

How can I fix the simple macro foo in (elisp)Eval During Expansion? None of the followings work: (defmacro foo1 (a) `(setq (eval ,a) t)) (defmacro foo2 (a) `(setq ,(eval a) t)) (defmacro foo3 (...

Get local cvs comment history when committing file/s in emacs

I often commit files with similar cvs comment but not in a single operation. I would like to able to bring up previous comments I ve used in a previous commit when I am in the process of writing a ...