Skip to content

Instantly share code, notes, and snippets.

@jdblischak
Last active October 28, 2024 14:16
Show Gist options
  • Save jdblischak/e0204226ab8a2b262b392bdb0bd4bdc5 to your computer and use it in GitHub Desktop.
Save jdblischak/e0204226ab8a2b262b392bdb0bd4bdc5 to your computer and use it in GitHub Desktop.
Hide supplement but retain cross-referencing with LaTeX

Hide supplement but retain cross-referencing with LaTeX

I was writing a scientific manuscript, and the journal did not want the supplement displayed with the main article. However, I needed the supplement to be processed concurrently in order to get the cross references to supplemental figures. I had trouble finding a solution to this problem, but eventually found this question and answer on tex.stachexchange.

This solved the problem, but was not automated. Thus I created a Makefile with some sed calls to automate it. Run make to build the document.

In my experience, the online submission systems for academic journals are cumbersome. Thus they won't be able to run this Makefile on their servers. I uploaded the two .aux files created with this Makefile, and the system was able to build the document with the cross-references included. Please leave a comment below if this also works for you!

Caveats

The example tex file is minimal. For example, if you are managing your references with BibTeX, you will need to add a call to bibtex and an additional call to pdflatex to the Makefile rule.

This is hacky and won't work for everything. For example, if your template has page numbers, the total number of pages listed will be the number of pages in the main article plus the supplement, even though the document produced in the end only contains the pages in the main article.

License and attribution

The code in main.tex is from egreg and newbie and is licensed under the CC BY-SA 3.0 (according to the StackExchange rules).

The Makefile is in the public domain (CC0). Please use and modify it as needed. No need for attribution.

Questions

Please feel free to leave a comment below. Unfortunately GitHub will not notify me if you do so, so if you'd like a response, please contact me by email.

\documentclass[letterpaper,11pt]{article}
\usepackage[nolists,nomarkers,figuresfirst]{endfloat}
\usepackage{filecontents}
\newcommand{\beginsupplement}{%
\setcounter{table}{0}%
\renewcommand{\thetable}{S\arabic{table}}%
\setcounter{figure}{0}%
\renewcommand{\thefigure}{S\arabic{figure}}%
}
\includeonly{} %%%%% Uncomment for removing the supplement table
\begin{document}
Table~\ref{tab:S1} but not Table~\ref{tab:1} should be in a separate pdf file. The rest is fine.
\begin{table}[ht]
\begin{tabular}{c}
Content 1
\end{tabular}
\caption{Caption 1}
\label{tab:1}
\end{table}
\newpage
\listoftables
\newpage
\processdelayedfloats
\begin{filecontents}{\jobname-support}
\beginsupplement
\renewcommand{\tablename}{Supporting Table}
\begin{table}[ht]
\begin{tabular}{c}
Content S1
\end{tabular}
\caption{Caption S1}
\label{tab:S1}
\end{table}
\processdelayedfloats
\end{filecontents}
\include{\jobname-support}
\end{document}
NAME := main
all: $(NAME).pdf
%.pdf: %.tex
sed -i s/'\\includeonly'/'%\\includeonly'/ $(NAME).tex
pdflatex -shell-escape $(NAME)
# Insert additional calls to pdflatex or bibtex here,
# depending on the complexity of your document
sed -i s/'%\\includeonly'/'\\includeonly'/ $(NAME).tex
pdflatex -shell-escape $(NAME)
clean:
rm -f $(NAME).aux $(NAME).log $(NAME).lot \
$(NAME).pdf $(NAME).ttt \
$(NAME)-support.tex $(NAME)-support.aux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment