SCRIPTS LaTeX make_latex_sampleΒΆ

# -*-Python-*-
# Created by eldond at 2018 Jun 21  14:01

"""
This script makes sample .tex files for an example OMFIT LaTeX build. It is called by build_latex_example.py.
It may be useful to use this script as a starting point / template for your own script for doing something real.
"""


defaultVars(mainroot='tex_sample', figure_name='figure', save_to=scratch)

# Standard blocks ------------------------------------------------------------------------------------------------------

# Preamble
opening = r"""\documentclass[10pt]{article}

% Include standard packages
% -----------------------------
\usepackage{amsmath}  % Equations and math
\usepackage{graphicx}  % Allows figures
\usepackage{hyperref}  % Links
\usepackage{xcolor}
\usepackage{float}  % Helps keep floats within sections
\usepackage{placeins}  % Provides FloatBarrier
\usepackage[margin=2cm]{geometry}
\usepackage[english]{babel}

\usepackage{blindtext}  % For making filler for this example

% Customization
% ----------------

% Color hyperlinks instead of putting ugly boxes around them
\hypersetup{
    colorlinks,
    linkcolor={red!50!black},
    citecolor={green!50!black},
    urlcolor={blue!50!black}
}
% Change date to ISO 8601  % NO_IRIS
\usepackage[yyyymmdd]{datetime}  % yyyymmdd  % NO_IRIS
\renewcommand{\dateseparator}{--}  % This is important to avoid using the / separator with yyyymmdd  % NO_IRIS

% Change style of citations and footnotes
\usepackage[super, comma]{natbib}
\renewcommand{\thefootnote}{\Alph{footnote}}

% Make references appear in table of contents
\usepackage[nottoc,numbib]{tocbibind}

% Custom macros for this document
\def\D3d{\mbox{DIII-D}}  %  Prevent line break between DIII- and D
\newcommand{\matrx}[1]{\overset\leftrightarrow{#1}}

% IOP template compatibility
\newenvironment{indented}{\begin{center}}{\end{center}}
\newcommand{\br}{ \hline }
\newcommand{\mr}{ \hline }

\pagestyle{headings}

\begin{document}

"""
if is_server(MainSettings['SERVER']['default'], 'iris'):
    opening = opening.split('\n')
    opening = [openin for openin in opening if '% NO_IRIS' not in openin]
    opening = '\n'.join(opening)

closing = r"""
\bibliographystyle{bib_style_d3dde}
\bibliography{sample_bib}
\end{document}
"""

# Title
title_part = r"""\title{{Sample OMFITlatex usage: {mainroot:}}}
\author{{{user:}}}

\maketitle""".format(
    mainroot=mainroot.replace('_', '\_'), user=os.environ['USER']
)

# Write introduction
intro = r"""
\begin{abstract}
Introductory statements to go in an abstract.
Words go here.
Did you know that breaking lines after each sentence makes the git diff of your LaTeX source easier to read?
Line breaks are your friends.
This is the last part of the abstract, which is now finished.
\end{abstract}
"""

# Template for figures
figure_template = r"""
\begin{{figure}}[!ht]
    \centering
    \includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{{figures/{filename:}}}
    \caption{{{caption:}}}
    \label{{{label:}}}
\end{{figure}}"""


# Body
body = r"""
\section{{The first section}}
This is sample body text of a LaTeX document, which you could set up and build with the OMFITlatex class in OMFIT.
\cite{{meneghini_2015_nf}}
You can script the generation of figures (see \ref{{fig:dummy}}) and LaTeX source.
So, it's nice to also be able to script the building of the final document.
You can make your module write your paper for you!

{info:}

{figure:}

\section{{TUTORIAL module settings}}

Settings for the TUTORIAL module at the time this document was generated are given in table~\ref{{table:settings}}
\input{{settings_table}}

\section{{blindtext}}
Blindtext is just random stuff to fill in the document and let you see how it gets formatted.
This section has no real content, unless figure~\ref{{fig:dummy}} floats into the middle of it.

\blindtext[1]

\begin{{equation}}
x = y
\label{{eqn:lol}}
\end{{equation}}

In between blind text, I give you equation~\ref{{eqn:lol}}.
This is quite an equation, as it is the first one in this whole document.
It even comes before equation~\ref{{eqn:bob}}, which appears below.

\begin{{equation}}
x = y^2
\label{{eqn:bob}}
\end{{equation}}

These equations are unrelated to figure~\ref{{fig:dummy2}}, which is just a copy of figure~\ref{{fig:dummy}}.

{figure2:}

\blindtext[2]

\blindtext[1]

\begin{{equation}}
x = y^3
\label{{eqn:charles}}
\end{{equation}}

Please note that equation~\ref{{eqn:charles}} is intended to be the last equation and we are almost done here.

\blindtext[2]

""".format(
    info=r'In order to use LaTeX curly braces AND python format tags, double up the ones for LaTeX: '
    r'\verb|{{LaTeX}}|, \verb|{python string formatting field}|',
    figure=figure_template.format(
        filename=figure_name, label='fig:dummy', caption=r'This is a figure caption, which describes the figure under which it appears.'
    ),
    figure2=figure_template.format(filename=figure_name, label='fig:dummy2', caption=r'This is a copy of figure \ref{fig:dummy}.'),
)


text = opening + title_part + intro + body + closing

save_to[mainroot + '.tex'] = OMFITascii(mainroot + '.tex', fromString=text)