0

I have a collection of about one hundred of short tex documents (1 or 2 pages each). I would like to reference them, not by their name, but by a number. This number is to be defined by the order of compilation.

Minimal example: Say one of my documents explains Lie groups, and another document talks about my grandfather's life who, let's pretend, invented Lie groups. I'd like to refer each document to the other, using the file name, and not the number which is arbitrary.

So if run first pdflatex lie_group.tex and then pdflatex grandfather.tex, I'd like to have lie_groups.pdf:

enter image description here

and grandfather.pdf:

enter image description here

On the reverse, if I compile grandfather.tex first, the output should be:

enter image description here

and

enter image description here

The question is how to define \magicFileNumber and \magicReference to produce the above-described outcome (coloring set aside) in the following way:

% this is lie_groups.tex
\documentclass{standalone}

\begin{document}
\textbf{Lie groups} (\textit{This is Document~\magicFileNumber}) 
Lie groups were introduced by my grandfather whose life is described in Document~\magicReference{grandfather}.
\end{document}

and

% this is grandfather.tex
\documentclass{standalone}

\begin{document}
\textbf{My grandfather} (\textit{This is Document~\magicFileNumber}) 
He invented Lie groups, see Document~\magicReference{lie_groups}.
\end{document}
7
  • 1) in your file file1.tex type \makeatletter \expandafter\@gobblefour\jobname \makeatother 2) i can't see the point \ref{file1}-->1? why don't just type 1?
    – touhami
    Aug 26, 2016 at 6:56
  • @touhami Because the file names I have given here are just dummy names. It could be 'history_Japan' and 'Lie_groups' instead of file1 and file2. Also, I don't want to change all the refs if I change the order of compilation. I'll check your answer a bit later.
    – anderstood
    Aug 26, 2016 at 11:09
  • But this is even easier, i will update my answer.
    – touhami
    Aug 26, 2016 at 11:40
  • now it's clear, \magicFileNumber go from 1 to ? you said that you have about one hundred?
    – touhami
    Aug 26, 2016 at 15:07
  • @touhami Yes, actually between one and two hundreds but I don't think that makes a difference. Of course each document only makes reference to a few others, if any.
    – anderstood
    Aug 26, 2016 at 15:11

1 Answer 1

1

Here is a solution. We need to creat a file files.tex

files.tex (files by order of compilation)


\newcounter{mtfile}
\refstepcounter{mtfile}
\label{liegroups}
\refstepcounter{mtfile}
\label{grandfather}
\refstepcounter{mtfile}
\label{otherfile}

Or

\newcounter{mtfile}

\newcommand*{\runpdflatex}[1]{%
\refstepcounter{mtfile}\label{#1}}

\runpdflatex{liegroups}
\runpdflatex{grandfather}
\runpdflatex{otherfile}

and input it in each file.

grandfather.tex

\documentclass{article}
\input{files.tex}

\begin{document}
\textbf{My grandfather} (\textit{This is Document~\ref{grandfather}}) 
He invented Lie groups, see Document~\ref{liegroups}.
\end{document}

Note that we don't need to copile all files.

2
  • So simple, and it works with any label (does not have to be the file name) and directory organisation. Labels should however not include underscore.
    – anderstood
    Aug 26, 2016 at 18:09
  • yes i forgot to note this.
    – touhami
    Aug 26, 2016 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .