14

How can I use following template in an org mode on latex. This will help me understand the org mode latex. Kindly explain the changes you make in the template so that I understand the org mode better (Teach me fishing!) Regards

\documentclass{article}
\usepackage{eso-pic}
\usepackage{fancyhdr}
\usepackage{blindtext} % just for the example
\usepackage[headsep=3cm,top=5cm]{geometry}
\usepackage{datatool}
% create sample csv file
\begin{filecontents*}{test.csv}
Id,myauthor,mydate,myaddress
1,Sebastian,12.12.2012,XYZ road,XYZ city
2,Rose,12.12.2013,XYZ road,abc city
\end{filecontents*}
% load data
\DTLloaddb{mydata}{test.csv}
\AddToShipoutPicture{%
  \AtTextUpperLeft{%
    \makebox(420,75)[lt]{%
      \footnotesize%
      \begin{tabular}{@{}*{3}{p{4.5cm}}@{}}%
      \textbf{Author}\newline\myauthor&%
      \textbf{Date of birth}\newline\mydate&%
      \textbf{Address}\newline\myaddress%
      \end{tabular}%
}}}
\pagestyle{fancy}
\newcommand{\myauthor}{user34083}
\newcommand{\mydate}{December 26, 1997}
\newcommand{\myaddress}{26 Washington Ave., Manhattan, New York.\newline United States of America}
% Define a command that fetches data for the row with the ID
% given in the argument
\newcommand*{\fetchdata}[1]{%
% fetch the first matching row
   \dtlgetrowforvalue{mydata}{\dtlcolumnindex{mydata}{Id}}{#1}%
% Lookup the required values from this row
   \dtlgetentryfromcurrentrow{\myauthor}{\dtlcolumnindex{mydata}{myauthor}}%
   \dtlgetentryfromcurrentrow{\mydate}{\dtlcolumnindex{mydata}{mydate}}%
   \dtlgetentryfromcurrentrow{\myaddress}{\dtlcolumnindex{mydata}{myaddress}}%
}

% fetch data for Id=2
\fetchdata{2}

\begin{document}

\blinddocument % just for the example
\end{document}
1

1 Answer 1

15

I have only tested this in versions pre-8.0.
I would highly recommend to read the org-mode manual for LaTeX exporting capabilities. It is very good: org-export-latex.

org-mode for Emacs has the optional LaTeX customization by using this:

#+LaTeX_HEADER: \newcommand\myaddress{...}

You can put as many header information lines as you please which in turn can build your custom LaTeX file on the fly.

#+LaTeX_HEADER: \newcommand\myaddress{...}
#+LaTeX_HEADER: \newcommand\myauthor{...}

Note that you can also use the above command to add packages.

Classes

Choosing the class for your org-file determines the packages that is used by a certain setup in your .emacs file.
To choose the org-class you do:

#+LaTeX_CLASS: article

To change the settings of the org-class article you add this to your .emacs file (example):

(add-to-list 'org-export-latex-classes
        '("article"
          "\\documentclass[10pt,article,oneside]{memoir}"
          ("\\chapter{%s}" . "\\chapter*{%s}")
          ("\\section{%s}" . "\\section*{%s}")
          ("\\subsection{%s}" . "\\subsection*{%s}")       
          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
          ("\\paragraph{%s}" . "\\paragraph*{%s}")
          ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
        )

You can also do:

(add-to-list 'org-export-latex-classes
         '("book"
           "\\documentclass[10pt]{memoir}"
           ("\\chapter{%s}" . "\\chapter*{%s}")
           ("\\section{%s}" . "\\section*{%s}")
           ("\\subsection{%s}" . "\\subsection*{%s}")       
           ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
           ("\\paragraph{%s}" . "\\paragraph*{%s}")
           ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
         )

which will let you do:

#+LaTeX_CLASS: article

Default packages for all classes

For customization of the default packages you use, you can do something like:

;; Default LaTeX export packages
(add-to-list 'org-export-latex-packages-alist '("" "amsmath"))

which will add the amsmath package to all your classes.

You can test with this small document and the above settings:

#+OPTIONS: TeX:t LaTeX:t
#+LaTeX_CLASS: article
#+LaTeX_HEADER: \usepackage{biblatex}
#+LaTeX_HEADER: \newcommand\myaddress{...}

* Hello
Hello to you
** Next time

* Not again

Which will give you something like this:

% Created 2013-12-18 Wed 10:42
\documentclass[10pt,article,oneside]{memoir}
\usepackage{amsmath}\usepackage{biblatex}
\newcommand\myaddress{...}

\title{test}
\author{Nick}
\date{18 December 2013}

\begin{document}

\maketitle
6
  • Is direct conversion to pdf and printing the pdf so generated is possible or I have to go through the cycle org--> latex--> pdf manually?
    – Vaibhav
    Dec 18, 2013 at 10:05
  • 3
    Sure that is possible: C-c C-e press l processes to LaTeX file, C-c C-e press p processes to LaTeX file and produces the pdf as well.
    – nickpapior
    Dec 18, 2013 at 10:11
  • The template I provided is a bit complex. Moreover the csv file that is being used is kept seperately. Kindly explain/ help convert the present template in org mode
    – Vaibhav
    Dec 21, 2013 at 9:33
  • 1
    @user34083 by principle I will not help convert your entire template. However, if you have any specific problems with it you should ask another question.
    – nickpapior
    Dec 21, 2013 at 10:20
  • @zeroth Could you please annotate whether your description is based on the new exporter (orgmode version >/= 8.0) or the old exporter (orgmode version < 8.0)?
    – Keks Dose
    Jan 3, 2014 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .