Temporarily changing document class in LaTeX/resetting pdfLaTeX - latex

How can I temporarily cause pdfLaTeX to forget everything that I've told it and start with a new document class?
I've modified the example environment from the lshort document:
\newwrite\examplesx#out
\newenvironment{examplesx}{%
\begingroup% Lets Keep the Changes Local
\#bsphack
\immediate\openout \examplesx#out \jobname.exa
\let\do\#makeother\dospecials\catcode`\^^M\active
\def\verbatim#processline{%
\immediate\write\examplesx#out{\the\verbatim#line}}%
\verbatim#start
}{%
\immediate\closeout\examplesx#out\#esphack\endgroup%
\noindent\makebox[\textwidth][l]{%
\begin{minipage}[c]{0.45\textwidth}%
\small\verbatiminput{\jobname.exa}
\end{minipage}%
\hspace*{0.1\textwidth}%
\framebox{%
\begin{minipage}{0.45\textwidth}%
\small\input{\jobname.exa}%
\end{minipage}
}%
}\vspace*{\parskip}%
}
and it mostly works, but I want to be able to do something like
\begin{examplesx}
\section{Section}
\end{examplesx}
and have it show up as a section in a box. I also would like it to typeset lists using the standard article style, even if I use it in beamer

I think that the easiest way of doing this is to compile some small document and then include the resultant pdf as an image into the larger document. Much simpler even if not exactly what you want. I have done this to show, in a Beamer presentation, what LaTeX articles look like.
Of course if its a REALLY simple document (e.g., a simple block of text) that you want to have inside beamer, I could recommend that you mimic the document with a TikZ "picture" that contains some text.

Maybe another approach: instead of trying to typeset things in beamer as if they would be done in article, simply typeset them with the article document class and include the result the in the beamer document.
With tcolorbox this can be done automatically:
% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}
\documentclass{beamer}
\usepackage[most]{tcolorbox}
\begin{document}
\begin{frame}[fragile]
\begin{tcblisting}{
comment only,
pdf comment,
compilable listing,
run pdflatex,
}
\documentclass{article}
\begin{document}
\section{Section Title}
test
\end{document}
\end{tcblisting}
\end{frame}
\end{document}

Related

Undefined references using pagesel in Latex

Let's say I have some labels in a part of the document that I exclude using pagesel. However, I want to reference them in the part that I am including. How is that possible?
Below is a minimum example which should print "This is reference 1", but instead prints "This is reference ??".
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[files,2-]{pagesel}
\title{Pagesel problem}
\begin{document}
\maketitle
\section{Introduction}
This is label \label{ref:label1}.
\cleardoublepage
This is reference \ref{ref:label1}
\end{document}
You can retain the labels from pages not shown by first compiling your whole document without the pagesel package and then, in a second step, use the pagesel package with the default nofile option:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[
%files,
2-]{pagesel}
\title{Pagesel problem}
\begin{document}
\maketitle
\section{Introduction}
This is label \label{ref:label1}.
\cleardoublepage
This is reference \ref{ref:label1}
\end{document}
Other possible approach: compile the complete document and then use a tool like pdftk to extract the pages you like.

LaTeX - control textwidth within the music environment

I am typesetting an A5 document, which includes a music environment as provided by musixtex.
I would like to reduce the linewidth/textwidth of just the music.
Here are a few things, that I have tried:
Put the music inside a minipage. This works fine for short excerpts but for longer music there might be the necessity of a page break, which a minipage doesn't have.
Use the \newgeometry command and subsequently \restoregeometry. That works, but apparently inserts a \newpage, which I also would like to avoid.
Use the changepage package which provides the command \adjustwidth. This works on the left side of the page, but the music then doesn't produce the linebreak at the desired position, but shifted to the right. I provide a MWE of this below.
Use a list-like environment like trivlist or itemize. This works on the left side of the page, but the music then doesn't produce the linebreak at the desired position, but shifted to the right, basically the same as above.
\documentclass{article}
\author{Myself}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{a5paper}
\geometry{twoside}
\geometry{inner=1.375cm}
\geometry{outer=1.375cm}
\geometry{top=1.5cm}
\geometry{bottom=1.5cm}
\usepackage{changepage}
\usepackage{musixtex}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{adjustwidth}{0.5cm}{0.5cm}
\begin{music}
\instrumentnumber{1}
\setstaffs1{1}
\generalmeter{\meterfrac{9}{4}}
\generalsignature{-1}
\nostartrule
\normalmusicsize
\nobarnumbers
\startpiece
\NOtes\qu{ff}\ql{j}\en\bar
\NOtes\qup{h}\cu{g}\qu{fedc}\en
\NOtes\qu{def}\en\bar
\NOtes\hup{gf}\en\rightrepeat
\NOtes\ql{jjj}\en\bar
\NOtes\hlp{k}\qu{h}\ql{ij}\en
\NOtes\qlp{j}\cl{i}\qu{h}\en\bar
\NOtes\hup{g}\qu{cdefgh}\en\bar
\NOtes\hup{gf}\en
\Endpiece
\end{music}
\end{adjustwidth}
\lipsum[2]
\end{document}
To me, both 3) and 4) seem to not work because musixtex doesn't understand/know the new settings for the linewidth etc.
More info: I am aware of the way that musixtex code has to be compiled, I am using a makefile that invokes pdflatex, musixflx and pdflatex again. This is not the cause of the problem.
Any help would be appreciated
You could use tcolorbox to create a breakable box:
\documentclass{article}
\author{Myself}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{a5paper}
\geometry{twoside}
\geometry{inner=1.375cm}
\geometry{outer=1.375cm}
\geometry{top=1.5cm}
\geometry{bottom=1.5cm}
\usepackage{changepage}
\usepackage{musixtex}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\tcolorboxenvironment{music}{breakable,text width=\dimexpr\textwidth-2cm,enhanced,grow to left by=-1cm,colframe=white,colback=white}
\begin{document}
\lipsum[1]
\begin{music}
\instrumentnumber{1}
\setstaffs1{1}
\generalmeter{\meterfrac{9}{4}}
\generalsignature{-1}
\nostartrule
\normalmusicsize
\nobarnumbers
\startpiece
\NOtes\qu{ff}\ql{j}\en\bar
\NOtes\qup{h}\cu{g}\qu{fedc}\en
\NOtes\qu{def}\en\bar
\NOtes\hup{gf}\en\rightrepeat
\NOtes\ql{jjj}\en\bar
\NOtes\hlp{k}\qu{h}\ql{ij}\en
\NOtes\qlp{j}\cl{i}\qu{h}\en\bar
\NOtes\hup{g}\qu{cdefgh}\en\bar
\NOtes\hup{gf}\en
\Endpiece
\end{music}
\lipsum[2]
\end{document}

\afterpage and \endfloat

How do I combine \afterpage and \endfloat to easily switch between having figures and tables at the end of the document or having them in the text?
I want to easily choose between my figures at the end of the document and my figures in the text. Because of that, sometimes I will use \afterpage package and other times I will use \endfloat would be nice to combine both.
Right now, all the times I try to run \endfloat when I have a clear page, I get the following message:
Argument of \efloat#xfloat has an extra }.
I already tried to include after page in the DeclareDelayedFloatFlavor, something like:
\DeclareDelayedFloatFlavor{afterpage}{figure}
It did not work.
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{afterpage}
% ---------------------
%figures at the end
% ---------------------
\usepackage[nolists]{endfloat}
% force landscape at the end
\begin{document}
{\afterpage{
\begin{figure}
\end{figure}
}
\end{document}
If you want to switch between having figures within the text and at the end, I suggest to only use the endfloat package. Commenting or commenting it's optional argument disable will allow you to quickly alternate between figures at the end or in the text.
I'm not entirely certain what the purpose of afterpage was in your example, but if you used it to move the figure to a separate page, this can conveniently be done with the p floating specifier.
\documentclass{article}
\usepackage[
disable
]{endfloat}
\begin{document}
test
\begin{figure}[p]
xxx
\caption{caption}
\end{figure}
test
\end{document}

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:

How to make 'appendix' appear in toc in Latex?

How to make word 'appendix' appear in the table of contents? Right now toc looks like this:
1 ......
2 ......
.
.
A .....
B .....
I would like it to be:
1 ......
2 ......
.
.
Appendix A .....
Appendix B .....
My latex source file structure is like this:
\begin{document}
\tableofcontents
\include{...}
\include{...}
\appendix
\include{...}
\include{...}
\end{document}
There's a couple of ways to solve this problem; unfortunately, I've only got a hack for you at this stage. One problem is that if we redefine the section number "A" to include the word "Appendix", it messes up the formatting of the table of contents. So instead, I've just defined a new sectioning command that prints the section without a number and inserts "Appendix X" manually.
Kind of ugly, but at least it works without having to change any markup :)
\documentclass{article}
\makeatletter
\newcommand\appendix#section[1]{%
\refstepcounter{section}%
\orig#section*{Appendix \#Alph\c#section: #1}%
\addcontentsline{toc}{section}{Appendix \#Alph\c#section: #1}%
}
\let\orig#section\section
\g#addto#macro\appendix{\let\section\appendix#section}
\makeatother
\begin{document}
\tableofcontents
\section{goo}
\label{a}
This is sec~\ref{a}
\section{har}
\label{b}
This is sec~\ref{b}
\appendix
\section{ji}
\label{c}
This is app~\ref{c}
\subsection{me}
does this look right?
\end{document}
For my thesis, I did the following:
\appendix
\addcontentsline{toc}{section}{Appendix~\ref{app:scripts}: Training Scripts}
\section*{Sample Training Scripts}
\label{app:scripts}
Blah blah appendix content blah blah blah.
Explanation: I manually added a line to the TOC so I would have "Appendix X:..." show up in my TOC. Then I excluded the actual section command from the TOC by using an asterisk.
This is probably most easily achieved by using the appendix
package, or the memoir class.
If you don't want to use a prepackaged solution, you'll have to
hack the sectioning commands. When I needed to do this for my
dissertation, I cloned the report class, and edited until I made
the margins lady happy. What you're looking for is the
definition of the \addcontentsline macro.
The appendix package is really good and simple solution. My answer can be helpful for who wants to change chapters numbering style, for example, with using cyrillic alphabet or roman digits. The appendices numbering style is hardcoded in the \#resets#pp command (I looked in sources here http://hal.in2p3.fr/docs/00/31/90/21/TEX/appendix.sty). I solved it by simple redefining this command to my own. Just add this code into your preamble:
\makeatletter
\renewcommand{\#resets#pp}{\par
\#ppsavesec
\stepcounter{#pps}
\setcounter{section}{0}
\if#chapter#pp
\setcounter{chapter}{0}
\renewcommand\#chapapp{\appendixname}
\gdef\thechapter{\Asbuk{chapter}} % changed
\else
\setcounter{subsection}{0}
\gdef\thechapter{\Asbuk{section}} % changed
\fi
\if#pphyper
\if#chapter#pp
\renewcommand{\theHchapter}{\theH#pps.\Asbuk{chapter}} % changed
\else
\renewcommand{\theHsection}{\theH#pps.\Asbuk{section}} % changed
\fi
\def\Hy#chapapp{\appendixname}%
\fi
\restoreapp
}
\makeatother
As a result,
Appendix A
Appendix B
Appendix C
...
will change to
Appendix A
Appendix Б
Appendix В
... etc
I'm not a latex expert, and I can't guarantee this code won't break something else.
Based on #Will Robertson's answer, the code below defines the same thing but for chapter and also fixes the fact that chapter* does not add to the header when using the fancyhdr package.
With this in the preable all issues are resolved.
\makeatletter
\newcommand\appendix#chapter[1]{%
\refstepcounter{chapter}%
\def\app#ct{Appendix \#Alph\c#chapter: #1}
\orig#chapter*{\app#ct}%
\markboth{\MakeUppercase{\app#ct}}{\MakeUppercase{\app#ct}}
\addcontentsline{toc}{chapter}{\app#ct}%
}
\let\orig#chapter\chapter
\g#addto#macro\appendix{\let\chapter\appendix#chapter}
\makeatother

Resources