All in one single org file
dineshadepu opened this issue · 1 comments
dineshadepu commented
Hi,
I did an alternate way of reproducing this. Basically we can use a single org file, and by using C-c C-e
get the pdf.
#+LaTeX_CLASS: article
#+OPTIONS: author:nil date:nil title:nil toc:nil
#+OPTIONS: ^:nil
#+LaTeX_HEADER: \usepackage{booktabs}
# % to include pdf/eps/png files
#+LaTeX_HEADER: \usepackage{graphicx}
# % useful to add 'todo' markers
#+LaTeX_HEADER: \usepackage{todonotes}
# % hyperrefs
#+LaTeX_HEADER: \usepackage{hyperref}
# % ----------------- Code blocks ----------------
# % nice source code formatting
#+LaTeX_HEADER: \usepackage{minted}
#+LaTeX_HEADER: \usepackage[utf8]{inputenc}
#+LaTeX_HEADER: \usepackage{listings}
#+LaTeX_HEADER: \usepackage{color}
#+LaTeX_HEADER: \definecolor{codegreen}{rgb}{0,0.6,0}
#+LaTeX_HEADER: \definecolor{codegray}{rgb}{0.5,0.5,0.5}
#+LaTeX_HEADER: \definecolor{codepurple}{rgb}{0.58,0,0.82}
#+LaTeX_HEADER: \definecolor{backcolour}{rgb}{0.95,0.95,0.92}
#+LaTeX_HEADER: \lstdefinestyle{mystyle}{
#+LaTeX_HEADER: backgroundcolor=\color{backcolour},
#+LaTeX_HEADER: commentstyle=\color{codegreen},
#+LaTeX_HEADER: keywordstyle=\color{magenta},
#+LaTeX_HEADER: numberstyle=\tiny\color{codegray},
#+LaTeX_HEADER: stringstyle=\color{codepurple},
#+LaTeX_HEADER: basicstyle=\footnotesize,
#+LaTeX_HEADER: breakatwhitespace=false,
#+LaTeX_HEADER: breaklines=true,
#+LaTeX_HEADER: captionpos=b,
#+LaTeX_HEADER: keepspaces=true,
#+LaTeX_HEADER: numbers=left,
#+LaTeX_HEADER: numbersep=5pt,
#+LaTeX_HEADER: showspaces=false,
#+LaTeX_HEADER: showstringspaces=false,
#+LaTeX_HEADER: showtabs=false,
#+LaTeX_HEADER: tabsize=4
#+LaTeX_HEADER: }
#+LaTeX_HEADER: \lstset{style=mystyle}
# % ----------------- Code blocks ----------------
# % change style of section headings
#+LaTeX_HEADER: \usepackage{sectsty}
#+LaTeX_HEADER: \allsectionsfont{\sffamily}
# % only required for orgmode ticked TODO items, can remove
#+LaTeX_HEADER: \usepackage{amssymb}
# % only required for underlining text
#+LaTeX_HEADER: \usepackage[normalem]{ulem}
# % often use this in differential operators:
#+LaTeX_HEADER: \renewcommand{\d}{\ensuremath{\mathrm{d}}}
# % allow more reasonable text width for most documents than LaTeX default
#+LaTeX_HEADER: \setlength{\textheight}{21cm}
#+LaTeX_HEADER: \setlength{\textwidth}{16cm}
# % reduce left and right margins accordingly
#+LaTeX_HEADER: \setlength{\evensidemargin}{-0cm}
#+LaTeX_HEADER: \setlength{\oddsidemargin}{-0cm}
# % reduce top margin
#+LaTeX_HEADER: \setlength{\topmargin}{0cm}
# % Increase default line spacing a little if desired
#+LaTeX_HEADER: \renewcommand{\baselinestretch}{1.2}
# % tailored float handling
#+LaTeX_HEADER: %\renewcommand{\topfraction}{0.8}
#+LaTeX_HEADER: %\renewcommand{\bottomfraction}{0.6}
#+LaTeX_HEADER: %\renewcommand{\textfraction}{0.2}
#+BEGIN_EXPORT latex
\title{\sffamily \textbf{Title -- template for orgmode latex production}}
\author{Hans Fangohr, Max Albert, University of Southampton}
\maketitle
\begin{abstract}
This is an abstract abstract, in the sense of only providing a
virtual abstract, also known as the interface. Somebody will have to
provide an inherited class that provides the real abstract.
We have placed the abstract in the paper.tex file, so that all the
content in the orgmode file \texttt{content.org} is organised into
sections, and they can be unfolded, re-arranged, etc (the abstract
doesn't go well into a section because it appears even before the
first section starts). If you prefer, you can move the abstract
latex definition as is into the \texttt{content.org} file, and all
will work as before.
\end{abstract}
#+END_EXPORT
* Introduction
Some introduction to the topic. Orgmode is cool, see http://orgmode.org fore details. URLs are converted into hyperrefs automatically (i.e. no need to use the \verb|\href{}{}| command).
* Method
** This document
\label{sec:method}
The overall workflow is this: the main part of the paper is in the
file ~content.org~.
This is translated by an (Emacs) script into a full LaTeX document with
name ~_content.tex~.
An extra (python) script strips off the LaTeX preamble and the
last few lines at the end of the document, and saves the
remaining middle part of the document as ~content.tex~.
The main latex file is ~paper.tex~, which contains the latex
preamble, all the style the requirements we or the journal may have,
the abstract, the bibliographystyle and bibliography uses the
\verb|\input{content.tex}| command to include the autogenerated latex
into the main document.
There is a Makefile that automises all of these steps. It may be useful to run a pdf viewer that watches and automatically updates ~paper.pdf~ on any change, and to have a loop (or the ~watch~ command that repeatedly calls ~make~, so that the pdf is re-created when the modified ~content.org~ file is saved).
** Subsections
Our document may well contain subsections. In fact, part of the joy of orgmode is that we can re-arrange sections and change their depth quite easily.
** Mention how to ignore a heading :ignoreheading:
Using the ~:ignoreheading:~ tag, we can use section headings which do
not appear in the final document.
** Say why this is useful :ignoreheading:
This is useful to 'label' paragraphs or sections to draft a document
while not wanting to reveal that label/title in the final version to the
reader.
** Details
We can use equations as if the orgmode source was \LaTeX{}, for example $f(x) = x^2$ or
\begin{equation}
\int f(x) \d x = C
\end{equation}
** Italics, bold, underline
Text can be emphasised using /italics/, *bold* or _underline_.
In org-mode these are written as ~/italics/~, ~*bold*~ and ~_underline_~.
** COMMENT
Note also the comment feature: sections that have titles starting with COMMENT are not included in the output, and can be used to record thoughts or drafts not to be shown in the LaTeX document.
* Results
** Tables
Tables are converted into tables:
| name | # |
|----------+----|
| Apple | 4 |
| Pears | 5 |
| Tomatoes | 16 |
** Figures
Figures can be included like this
file:figures/icon.png
Or we use the latex command directly:
\includegraphics[width=2cm]{figures/icon.png}
We can also provide guidance to orgmode how we would like the figure included (see http://orgmode.org/manual/LaTeX-specific-attributes.html for details):
#+ATTR_LATEX: :width 2cm :options angle=90
file:figures/icon.png
If you prefer, you can inculde the full float figure environment as
raw latex into the orgmode file. Here is an example for such a figure,
and then we can refer to it through its figure number
\ref{fig:myfigure}.
\begin{figure}
\centering
\includegraphics[width=0.1\columnwidth]{figures/icon.png}
\caption{The skyline\label{fig:myfigure}}
\end{figure}
** Figure and Table environments
The ~+CAPTION~ directive instructions orgmode to create a caption, and wrap up the following graphic or table into a Table or Figure environment.
#+CAPTION: This is the caption for the next table (or link)
#+NAME: tab:basic-data
| Apples | 1 |
| Bananas | 3 |
|---------+---|
| Fruit | 4 |
#+CAPTION[Short form]: This is the caption for the next Figure
#+NAME: fig:example
#+ATTR_LATEX: :width 2cm :options angle=90
file:figures/icon.png
We have just created figure \ref{fig:example}.
** Code
We can also include code. Again, it can be done directly from orgmode (and the option to also execute the code from within orgmode and include the output is exciting, but goes beyond the purpose of this template for document writing in orgmode. If you want to explore this further, look here: http://orgmode.org/manual/Working-with-source-code.html#Working-with-source-code
\begin{figure}
\footnotesize
\inputminted[bgcolor=white,frame=lines]{python}{code/example1.py}
\normalsize
\caption{An example script in Python. \label{fig:code-example1}}
\end{figure}
Figure \ref{fig:code-example1} shows some code.
** Include literal LaTeX
#+LATEX: If necessary, we can use the \verb|#+LATEX:| directive, to send a string directly to LaTeX, i.e. unmodified by orgmode.
#+BEGIN_LATEX
We can also create a literal \LaTeX{} block like this one.\footnote{See \href{http://orgmode.org/manual/Quoting-LaTeX-code.html}{http://orgmode.org/manual/Quoting-LaTeX-code.html} for more details}.
#+END_LATEX
** More results
Of course we can cite work \cite{authorX2016}.
* Discussion
Coming back to the method outlined in section \ref{sec:method}, it may
well be possible to achieve a similar setup without the Python script
extracting the main part of the autogenerated document etc, and
include all the required latex setup, extra packages, into special #+
commands in the orgmode file. However, I have found it efficient to be
able to use journal latex templates directly, and thus came up with
this arrangement. Not perfect, but a functional start.
* Summary
I like using orgmode to author documents as the orgmode mark up is less intrusive (and overall fewer characters to type!) than the \LaTeX{} mark up. Rearranging sections, and changing the depth (i.e. move sections to subsections etc) are trivial in orgmode. Overall, orgmode allows me to focus more on the content of the document and its structure.
* Acknowledgements
Thanks to Sam Sinayoko for introducing me to his way of creating
beamer latex slides from orgmode, and who wrote the original elisp
script that executes the conversion of orgmode files to LaTeX. Thanks
also to Maximilian Albert, who helped tidying up the Makefile.
\newpage
* TODO
Sometimes, a section with things to do is useful; with the understanding that this is completed and removed before the document is finished. (Or changed into a COMMENT section, so that it doesn't export to latex.)
An orgmode todo list (which can be nested) looks like this
- TODO [2/3]
- [X] create github repository
- [X] write up the setup for this document
- [ ] Save planet [0/3]
- [ ] understand challenge
- [ ] find solution
- [ ] implement it
bibliographystyle:unsrt
#+BEGIN_EXPORT latex
\end{document}
#+END_EXPORT
This will simplify the code conversion, creating new files and many more.
fangohr commented
Thank you.