How to create a LaTeX class with default parameters? - latex

I've learnt how to use LaTeX at the user level, but wanted to package the recurring code (resulting mostly from the styling of the cover) in a class file.
Therefore, I tried the following simple example class file:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test}[2018/10/12 v0.1 Test class]
\PassOptionsToClass{12pt}{report}
\ProcessOptions
\LoadClassWithOptions{report}
Although this works if I pass the size I want, if I omit it, it defaults to 10pt, instead of 12pt that I want. Do you know how to make the default become the 12pt, and still work if I decide to give it another size option?

Based on https://tex.stackexchange.com/a/123623/36296 you could so something like
\RequirePackage{filecontents}
\begin{filecontents}{test.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test}[2018/10/12 v0.1 Test class]
\DeclareOption{10pt}{\def\test#ptsize{10pt}}
\DeclareOption{11pt}{\def\test#ptsize{11pt}}
\DeclareOption{12pt}{\def\test#ptsize{12pt}}
\ExecuteOptions{12pt}
\ProcessOptions
\PassOptionsToClass{\test#ptsize}{report}
\LoadClass{report}
\end{filecontents}
\documentclass{test}
\begin{document}
test
\end{document}

Related

Export tex document which uses the exam class (Part 2)

I would like to export a text document which uses the exam class to markdown. To do so, I am currently using a workaround which was suggested in this answer, which relies on pseudo-definitions which in turn overwrite the definitions of the exam class such that pandoc can produce a clean markdown file.
Although, the workaround works for the suggested multiple-choice questions, I cannot adopt the solution to work for text with “fillin gaps” such as the document below:
\documentclass[answers]{exam}
\usepackage{minted}
\let\oldpart\part
\renewcommand{\part}[1][]{\oldpart[#1]{}}
\begin{document}
\begin{questions}
\question Exercise 1
\begin{parts}
\part[1] This fills in the \fillin[blanks][3cm]
\end{parts}
\end{questions}
\end{document}
If I use the following pseudo-definitions in a separate file:
% ignore \part
\renewcommand{\part}[0][1]{}
% Treat checkboxes like an itemized list
\newenvironment{checkboxes}{\begin{itemize}}{\end{itemize}}
\renewcommand{\CorrectChoice}{\item ☒ }
\renewcommand{\choice}{\item ☐ }
\renewcommand\fillin[2][{}]{\textbf{#1}}
I get the following broken markdown output
This fills in the **blanks**3cm\]
Moreover is there a way for pandoc to ignore \begin{parts} and \end{parts} so that there are no ::: in the final Markdown file?
The \fillin problem can be solved with
\newcommand{\fillin}[1][1]{\textbf{#1}\noop}
whereas the parts div can be removed with
\newenvironment{parts}{}{}

LaTeX: Cite, but don't reference

I'm producing a set of documents in LaTeX, and I would like to provide a single, global bibliography page for the whole set. This is because each document is page-limited: I don't want to take up space with references at the bottom of each one.
This means in each case, I would like to cite in the text, but not produce a reference at the end. I am using bibtex/natbib to handle the referencing.
Simplest example:
\documentclass[]{article}
\bibliographystyle{/usr/share/texmf/bibtex/bst/natbib/plainnat.bst}
\usepackage{natbib}
\begin{document}
In \citet*{MEF2010} I described the method.
\bibliography{bibliography.bib}
\end{document}
How can I do this? Essentially I just want it to cite correctly:
In Bloggs, Blagg and Blog (2010) I described the method.
But not add a references section at the end. Any ideas?
Thanks,
David
Instead of using \bibliography{bibliography.bib} you can try \nobibliography{bibliography.bib}.
You still need to enter the path so it can make the cross-references.
It happens due to missing packages. If you want to resolve the problem then enable the automatic installation packet. After that,First, you run the BibTeX file and generate the Pdf file (instead of pdfLatex file) and then pdfLatex to Pdf

Latex Beamer: How is it possible to make piece of text in a frame in italics?

I am using Beamer in order to make a presentation. In one of the frames I want to write something like this:
"Italics is like that"
I used a command \it of Beamer for doing this:
\it{Italics} is like that
But as a result I get:
"Italics is like that"
Is it possible to make italics only a piece of text?
I believe you're looking for \textit{}.
Also, in the future, consider asking LaTeX questions on the TeX - LaTeX Stack Exchange site.
\it is a switch, it changes the font series starting from the point it was issued till the end of the current block. Therefore you have to enclose the block of text it should affect:
{\it Italics} is like that
Alternatively you can use \textit as suggested by gotgenes which only affects the text passed to the command within braces:
\textit{Italics} is like that.
What about \emph{text} ?

How to override LaTeX template's string constants

I'm typesetting my CV using the europecv LaTeX class. I don't actually need to conform to the EU's standardized CV form, but I like the general layout of it. One thing that bothers me about the class is how it sets certain headings, for instance
Surname(s) / First name(s): Smith, John
Where I'd rather have
Name: John Smith
I've found that these string constants for English are defined in a file called "ecven.def" thus:
\def\ecv#infosectionkey{\ecv#utf{Personal information}}
\def\ecv#namekey{\ecv#utf{Surname(s) / First name(s)}}
\def\ecv#addresskey{\ecv#utf{Address(es)}}
\def\ecv#telkey{\ecv#utf{Telephone(s)}}
\def\ecv#mobilekey{\ecv#utf{Mobile}}
I guess I could just edit this file to change them, but that seems like the wrong approach. I tried to do this at the top of my document:
\renewcommand{\ecv#namekey}{\ecv#utf{Name}}
which gives this error:
./eurocv.tex:22: LaTeX Error: Missing \begin{document}.
And I've tried this:
\def\ecv#namekey{\ecv#utf{Name}}
which doesn't give an error, but doesn't change the output. Any ideas?
You need to use the \makeatletter and \makeatother commands wrapping your changes.
\makeatletter
\def\ecv#namekey{\ecv#utf{Name}}
...
\makeatother

How to force line wrapping in listings package?

I have a problem concerning the listings package in latex. I need to embed a source code of the following XML document http://www.sparxsystems.com.au/downloads/profiles/EP_Extensions.xml in my master thesis' appendix. The problem is, no matter what options I pass to the package, I don't seem to be able to fit it on the page. The lines in the listing are too long, and the listings package doesn't wrap them, which seems odd... What combination of options will do the trick?
At the moment I use the following lstset instruction:
\lstset{
breakindent=0em,
language=XML,
basicstyle=\footnotesize,
numbers=left,
numberstyle=\footnotesize,
stepnumber=2,
numbersep=5pt,
backgroundcolor=\color{white},
showspaces=false,
showstringspaces=false,
showtabs=false,
frame=single,
tabsize=2,
captionpos=b,
breaklines=true,
breakatwhitespace=true,
breakautoindent=true,
escapeinside={\%*}{*)},
linewidth=\textwidth
}
Which, with no other options set, and combined with the following command:
\lstinputlisting{EP_Extensions.xml}
Lists the given file's source to the following output:
I just had this problem...
breaklines worked for me, though you do need to set it to true - the default is false:
\lstinputlisting[style=Python,
caption=My Class,
label={mine.py},
breaklines=true,
]{../python/mine.py}
is pretty much what I used
I had this problem and this page ranks highly on google so here was the solution for me:
I had the following inclusion: \usepackage[none]{hyphenat} which causes the issue described above. I was using it to fix the problem of latex automatically breaking lines in the middle of a word, which looks really stupid in some circumstances.
After much searching for an alternative to this solution I found nothing suitable and settled for properly broken lines but badly placed hyphenation.
Not a great answer, but one idea is to word wrap the source code before including it. If you're on linux, the command fold can be used for this. Clearly this works best if the text is in a fixed width font, which i would recommend in any case for code listings.
A followup to Aaron's answer. I was using basicstyle=\ttfamily for my listings. I was therefore able to permit line breaking by changing
\usepackage[none]{hyphenat}
to
\usepackage[htt]{hyphenat}
% ^^^
The hyphenat docs describe that the htt option "enables hyphenation of ... text typeset via either \texttt or \ttfamily." In my use case, I didn't see any hyphenation in my listings, but I did get the breaking.

Resources