1

I remember learning how to to this long time ago, but I can't figure now how.

And google search is not turning anything.

I have a standalone latex file which starts with subsection because this file is part of a larger document which will be all bundled using the standalone package into one large document.

But when I build this specific file on its own, I want the subsection to become section and the subsubsection to become subsection. This is what I tried

\documentclass[11pt,titlepage]{article}%
\usepackage{standalone}
\standalonetrue 

\ifstandalone %building this as standalone?
   \renewcommand{\subsection}{\section}
   \renewcommand{\subsubsection}{\subsection} 
\fi 

\begin{document}

\subsection{Problem 1} %this should become \section when standalone
\subsubsection{Part a} %this should become \subsection when standalone
A
\subsubsection{Part b}
B     
\end{document}

But when I compile the above using lualatex then both the subsection and the subsubsection become section.

Mathematica graphics

I also tried

\ifstandalone 
\let\subsection\section
\let\subsubsection\subsection
\fi 

same result.

What is the correct way to do this? The fix must only be in the preamble as shown above, nothing after the \begin{document}

Using TL 2018

2

\renewcommand shouldn't work because it expands to whatever those are at the time you end up using them (ie, when you use the commands in your document, everything gets redefined to section). \let changes the left to become whatever the right is at that moment. With

\let\subsection\section
\let\subsubsection\subsection

\subsection becomes \section, and then \subsubsection becomes \subsection (which you just made \section). It should work to reverse the \lets:

\let\subsubsection\subsection
\let\subsection\section

Then \subsubsection gets the same definition as \subsection, and \subsection gets the same definition as \section.

But why not just

\ifstandalone
\section{dummy section title}
\fi

instead of redefinitions?

  • Thanks. I remember now. It was the order trick. I've done this before as I said, but forgot how :) . As for why not the second way you show, it is because having it redefined in preamble means I do not need to add the code everywhere again in the document around each subsection, etc...in preamble, it is done once only. – Nasser Sep 14 '18 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.