using command line arguments to include/exclude text sections - latex

I have a main document defined of which I need to extract different versions. For example, in:
\section*{5\\animalia}
\vspace{\oneline}
\includegraphics[page={33}, trim=1cm 0 0 0]{\pdfsource}
\includepdf[page={34-37}]{\pdfsource}
the last line would be compiled only if I would run pdflatex with the argument AA.
There should be around 20 different versions to prepare, so it would be great if I could compile all these in a batch, instead of preparing 20 different files. There are no common elements to select, so the lines from AA will all be different ones from AB or AJ.
I had a look at \newcommand and \xparse, but I think I didn't find exactly what I needed. Any suggestions?
One other detail: the argument would also be passed to a text line at the start, namely:
\subsection*{ARGUMENT}
would print as AA. I think that is easy to do, but I couldn't also find a concrete example.

If you compile the following with
pdflatex "\newcommand{\version}{KK}\input{filename.tex}"
you can test for the value of \version:
\documentclass{article}
\usepackage{ifthen}
\ifdefined\version
\else
\def\version{AK}
\fi
\begin{document}
\section{\version}
\ifthenelse{ \equal{\version}{KK} }{
KK version
}{
other version
}
\end{document}

Related

Latex ClassicThesis - The numbering of the paragraphs does not appear

I need one more numbered level for my report. I used \paragraph{title} but it only appears without numbering.
In the config file, the paragraph is described as:
\titleformat{\paragraph}[runin]
{\normalfont\normalsize}{\theparagraph}{0pt}{\spacedlowsmallcaps}
I believe that the command \theparagraph is responsible for the numbering. Why doesn't it appear?
I searched the net for answers and tried the following commands (at once) before the beginning of the document:
\setcounter{secnumdepth}{\paragraphnumdepth}
Replace the previous command to get rid of run-in with:
\titleformat{\paragraph}
{\relax}{\textsc{\MakeTextLowercase{\theparagraph}}}{1em}{\normalsize\itshape}
\renewcommand{\theparagraph}{\thesubsection.\arabic{paragraph}}
I put the last two commands in \makeatletter and \makeatother.
The paragraph name appears like the section names now, but still no numbers. Any ideas? Here is a small example that works because I didn't include the classicthesis config files.
\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\setcounter{secnumdepth}{\paragraphnumdepth}
\begin{document}
\chapter{Chapitre}
\section{Introduction}
\subsection{Première sous-partie}
\subsubsection{Un cran en dessous}
\paragraph{Paragraphe with number: what I would like in my report}
Functional here because the problem clearly comes from the two classicthesis config files...
\end{document}
Thank you

Left justification of nomenclature description in LaTeX

I'm using a LaTeX template (provided by ASME) to write a conference paper.
The asme2e.cls class defines a "nomenclature" environment as follows:
% Nomenclature environment
\newbox\tempbox
\newenvironment{nomenclature}{%
\newcommand\entry[2]{%
\setbox\tempbox\hbox{##1.\quad}
\hangindent\wd\tempbox\noindent{##1}\quad\ignorespaces##2\par}
\section*{NOMENCLATURE}}{\par\addvspace{12pt}}
which is used, in the .tex source file, as follows:
\begin{nomenclature}
% [...]
\entry{$C_{visc}$}{Viscous friction coefficient.}
\entry{$M$}{Spool mass.}
% [...]
\end{nomenclature}
resulting in the description texts not being left justified (since a fixed horizontal space is inserted between the symbol (e.g.: M) and the description (e.g.: Spool mass.), but the symbols have different lengths (e.g.: Cvisc is longer than M).
Is there a way to fix the class to have left-justified descriptions?
(I did a few experiments with \dimexpr and the calc package, but just got a bunch of errors).
(I also asked ASME if they could provide an updated template, but I'm still waiting for their feedback...)
I couldn't solve the problem, but I found a "quick and dirty" workaround, using the Tabbing and setspace packages.
Here is the new .tex source:
%[...]
\usepackage{Tabbing}
\usepackage{setspace}
%[...]
\begin{nomenclature}
{\setstretch{1.1}
\begin{tabbing}
\noindent
% [...]
\entry{$C_{visc}$}\quad\quad\={Viscous friction coefficient.}\\
\entry{$M$}\>{Spool mass.}\\
\entry{$v$}\>{Spool velocity.}\\
% [...]
\end{tabbing}
} % end \setstretch
\end{nomenclature}
%[...]
(Clearly, I'm completely bypassing the \entry command defined by the asme2e.cls class for the nomenclature environment).
I also tried to edit the asme2ej.cls file but nothing working for me. Then I ended up using the tabbing and set space packages. However, I did not use the \setstretch, and my document compiled just fine.
%[...]
\usepackage{Tabbing}
\usepackage{setspace}
%[...]
\begin{nomenclature}
\begin{tabbing}
\noindent
\entry{XYZ}\quad\quad\={This is an example}\\
\entry{PQR}\>{This is an example}\\
\entry{ZXC}\>{This is an example}\\
\entry{CVN}\>{This is an example}\\
\end{tabbing}
\end{nomenclature}
%[...]
I ran into a similar issue when submitting a paper to an ASME journal. My solution was to edit the asme2e.cls file:
\newenvironment{nomenclature}{%
\newcommand\entry[2]{\noindent\hbox to 0.05\textwidth{##1}\ignorespaces##2\par}
\section*{Nomenclature}}{\par\addvspace{12pt}}
You can change the amount of indentation by changing "0.05\textwidth".
I'm not sure if this is what you're asking, but see the following MWE:
\documentclass[12pt]{article}
\newlength{\nomenlabelindent}
\setlength{\nomenlabelindent}{4em}
\newenvironment{nomenclature}{%
\newcommand\entry[2]{%
\hangindent\nomenlabelindent\noindent\makebox[\nomenlabelindent][l]{##1\quad}\ignorespaces##2\par}%
\section*{NOMENCLATURE}}{\par\addvspace{12pt}}
\begin{document}
\begin{nomenclature}
\entry{$A$} {Parameter}
\entry{$B$} {Parameter}
\entry{$C$}{Parameter}
\entry{$D$}{Parameter}
\entry{$E$}{Parameter}
\end{nomenclature}
\end{document}
Output:
Nomenclature

How can I mention the name of a LaTeX command in my beamer presentation?

I am preparing a presentation in beamer with gradientframe package. But it's giving me an error.
How can I write the name of the command in \frame?
\begin{frame}
\frametitle{Introduction}
The gradientframe package provides a command, \gradientframe for simple and discreet
rectangular grayscale gradient frames around objects, such as figures or tables, to set
them apart from the surrounding text.
\end{frame}
As in several answers to the linked question (thanks #Bas Swinckels), the way advised to insert a backslash \ in the output is to use \textbackslash in the source.
Then, you can use (or not) just \texttt{} (rather than verbatim or else) to mark command names.
Finally, if you have to mention these command name(s) many times in your slides, you may want to put the above two in a newcommand:
\documentclass{beamer}
\newcommand{\mycomm}[1]{\texttt{\textbackslash #1}}
%\newcommand{\commgf}{\texttt{\textbackslash gradientframe}}
\begin{document}
\begin{frame}
\frametitle{Introduction}
... a command, \textbackslash gradientframe for simple ...
or:
... a command, \texttt{\textbackslash gradientframe} for simple ...
or, better:
... a command, \mycomm{gradientframe} for simple ...
%... a command, \commgf{} for simple ...
\end{frame}
\end{document}
This code gives you:

LaTeX \newcommand default argument: is empty?

I'm trying to write a simple example command that prints nothing without an argument, but with an argument it surrounds it with something.
I've read that the default value should be \#empty and the simple \ifx\#empty#1 condition should do the job:
\newcommand{\optarg}[1][\#empty]{%
\ifx\#empty#1 {} \else {(((#1)))} \fi
}
\optarg % (((empty)))
\optarg{} % (((empty)))
\optarg{test} % (((empty))) test
The latter three commands all print the empty word for some reason, and I want the first two to print nothing and the last to print (((test))).
I'm using TeXLive/Ubuntu. An ideas?
Try the following test:
\documentclass{article}
\usepackage{xifthen}% provides \isempty test
\newcommand{\optarg}[1][]{%
\ifthenelse{\isempty{#1}}%
{}% if #1 is empty
{(((#1)))}% if #1 is not empty
}
\begin{document}
Testing \verb|\optarg|: \optarg% prints nothing
Testing \verb|\optarg[]|: \optarg[]% prints nothing
Testing \verb|\optarg[test]|: \optarg[test]% prints (((test)))
\end{document}
The xifthen package provides the \ifthenelse construct and the \isempty test.
Another option is to use the ifmtarg package (see the ifmtarg.sty file for the documentation).
Using the LaTeX3 xparse package:
\usepackage{xparse}
\NewDocumentCommand\optarg{g}{%
\IfNoValueF{#1}{(((#1)))}%
}
In the underlying TeX engine with which LaTeX is written, the number of arguments a command can take is fixed. What you've done with the default [\#empty] is ask LaTeX to examine the next token to see if it is an open square bracket [. If so, LaTeX takes the contents of square brackets as the argument, if not, the next token is put back into the input stream and the default \#empty argument is used instead. So to get your idea to work, you have to use square brackets to delimit the optional argument when present:
\optarg
\optarg[]
\optarg[test]
You should have better luck with this notation.
It's annoying that you can't use the same brackets for an optional argument as you use for a required argument, but that's the way it is.
\documentclass{article}
\usepackage{ifthen} % provides \ifthenelse test
\usepackage{xifthen} % provides \isempty test
\newcommand{\inlinenote}[2][]{%
{\bfseries{Note:}}%
\ifthenelse{\isempty{#1}}
{#2} % if no title option given
{~\emph{#1} #2} % if title given
}
\begin{document}
\inlinenote{
simple note
}
\inlinenote[the title]{
simple note with title
}
\end{document}

Latex listings-package format option for uppercase keywords

I use the listings package to insert source code. I would like to print all keywords uppercase in the output, regardless of the case in the input.
The manual states that
keywordstyle=[number][*]style
produces just what I want. However the following (almost) minimal example does not work.
if I set keywordstyle to "[1][]{\bfseries}" I end up with "[]" in front of every keyword
and "[*]{\bfseries}" gives me an asterisk in the start of the document.
I also tried "\MakeUppercase" and "{\MakeUppercase}" for keywordstyle which resulted in several errors, the first being:
! Incomplete \iffalse; all text was ignored after line 11
Minimal example:
\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{KA_assembler}
{morekeywords={add,and,or,xor},
keywordstyle=[1][*]{\bfseries},
sensitive=false,
}
\lstset{language=KA_assembler}
\begin{document}
\begin{lstlisting}
and %r1, %r2
xor %r2, %r3
and %r4, %r5
\end{lstlisting}
\end{document}
I use Miktex for compilation of the tex files. So how do I force uppercase for Keywords?
In the manual, the brackets around the * look a bit different then the brackets around number. The reason is that the brackets around * are not meant to be used in the latex code, they just indicate that the presence of the * is optional. So try
keywordstyle=[1]*\bfseries
or
keywordstyle=*\bfseries
- it worked for me.

Resources