4

Background:

The document that I am currently writing is getting pretty big, so I decided to split it.

I've tried \include and \input commands, but the problem still remains to be solved.

I have split Chapter one to file 1.tex from the main document, and include it with the mentioned commands (tried both).

Main file is marked as Master.

I am having cross referencing (equations, labels and so on) between different sections.

Problem

In file 1.tex, I am referencing labels and equations from different parts on the main document - before and after the \include command.

However, the auto-complete is only working for labels and equations that are mentioned before \include command, but not working for the ones which are inserted in main file after \include command.

Is there any way to fix this?

MWE:

Main.tex:

\documentclass{article}
\begin{document}
\section{1st}
\begin{equation}
    a=1
    \label{eq:1}
\end{equation}
all the equations of the paper: \ref{eq:1}, \ref{eq:2}, \ref{eq:3}

\include{2}

\section{3rd}
\begin{equation}
    a=3
    \label{eq:3}
\end{equation}
all the equations of the paper: \ref{eq:1}, \ref{eq:2}, \ref{eq:3}
\end{document}

2.tex:

\section{2st}
\begin{equation}
    a=2
    \label{eq:2}
\end{equation}
all the equations of the paper: \ref{eq:1}, \ref{eq:2}, \ref{eq:3}

In Main.tex autocomplete is working (when writing \ref...) for all 3 equations, but in 2.tex auto-complete is working only for the second one.

9
  • How many times have you run pdflatex?
    – dustin
    Aug 6, 2013 at 16:10
  • I have set it up to run like: pdflatex -> bibtex -> pdflatex -> pdflatex
    – Fortaz
    Aug 6, 2013 at 16:13
  • Is it possible to include a small MWE which can reproduce your situation: In this way you may solve the problem easily also. BTW Latest version of TeXmaker is 4.0.3 Aug 6, 2013 at 16:23
  • Do you mean the auto-complete in Texmaker, or the compiled pdf? If in Texmaker, the autocomplete will not work because Texmaker doesn't know that you've defined those commands in a different file. I don't know of a way to get it to parse those commands and allow auto-complete.
    – darthbith
    Aug 6, 2013 at 17:42
  • 1
    Yes, you are right, The \label{eq:1} and \label{eq:3} in main.tex is not available for auto-completion in 2.tex incase you wish report/contribute this strange issue with same MWE. But i did not encounter this problem if you place \section{1st} in child1.tex, \section{2nd} in child2.tex and \section{3rd} in child3.tex auto-completion works perfectly. Then new main.tex has only \include{child1.tex}\include{child2.tex}\include{child3.tex} Aug 6, 2013 at 18:52

5 Answers 5

3

Have your main document in the current editing window. Now select Options-Define Current >Document as "Master Document". This will do what you are asking for, I just did it. Also, now you can compile from any of the files and it will work.

Just worked for me, thanks heaps. That was really annoying me. Much happier now...

1

AFAIK this is one of the major shortcommings of TM and TS. My guess is that is it looking in the .aux file of the current file. If there are any \@input{file.aux} it will look there too.

But this means, when you are in 2.tex the rest of the document is not referenced in this particular .aux.

Then a master document is set, TM really ought to go back to the master files .aux when it is looking for labels and such.

What happens if you are not using \include?

EDIT:

Just tested it using the latest TM. No luck. It seems even worse. It is looking directly at \label's in 2.tex.

Try adding

\newcommand\test[1]{\label{#1}}

and in 2.tex replace \label{eq:2} by \test{eq:2}. Now TM cannot find any labels.

As already mentioned, it really should be looking that the .aux files instead. It will miss label=key in listings etc.

Personally I use Emacs, and I'm actually not quite sure where it gets its label information, but it does handle multiple files just fine (it may also be looking for \label).

0
1

As previously answered, Texmaker does not seem to reference labels declared in included files in the structure of the document.

A workaround that you can use, however, is to use the way Texmaker detects existing labels to trick it into thinking that you are declaring a label inside your document when you are, in fact, not.

Let me explain by reusing your MWE.

Main.tex :

\documentclass{article}
\def\ProvideLabels#1{}
\def\LabelsAvailable#1{}
\begin{document}
\section{1st}
\begin{equation}
    a=1
    \label{eq:1}
\end{equation}
all the equations of the paper: \ref{eq:1}, \ref{eq:2}, \ref{eq:3}

\include{2}\ProvideLabels{\label{eq:2}}

\section{3rd}
\begin{equation}
    a=3
    \label{eq:3}
\end{equation}
all the equations of the paper: \ref{eq:1}, \ref{eq:2}, \ref{eq:3}
\end{document}

2.tex :

\LabelsAvailable{\label{eq:1}\label{eq:3}}
\section{2st}
\begin{equation}
    a=2
    \label{eq:2}
\end{equation}
all the equations of the paper: \ref{eq:1}, \ref{eq:2}, \ref{eq:3}

Adding \def\ProvideLabels#1{} and \def\LabelsAvailable#1{} in the preamble of the document creates two commands to which you can pass arguments and that do nothing with it. In other words, whatever you write in it, only Texmaker will be interested in it, as it does not rely on proper latex compiling to see whether the \label{stuff} you wrote will actually be used by latex.

Now, you can use \ProvideLabels{\label{label1} \label{label2}} in your main document after calling a \include to explain to Texmaker which labels were created within what you included. In the same logic, you can use \LabelsAvailable{\label{label1} \label{label2}} within your included documents to explain Texmaker what labels have been created either in your main document or in other included documents.

You can use the same logic to explain to Texmaker the structure of the document itself, but usually, it is less important when writing the document.

I do realize that this solution is very high maintenance, very hacky and absolutely non ideal, but I could myself not find better. Ideally, of course, Texmaker should simply be more clever about this kind of things.

0

"Edit" menu of Texmaker -> "Refresh structure"

(and of course the file 1.tex is supposed to be 2.tex...)

1
  • user27168, thank You. I have already tried it, however - with no luck... And of course, 2.tex it is...
    – Fortaz
    Aug 7, 2013 at 9:57
0

Have your main document in the current editing window. Now select Options-Define Current Document as "Master Document". This will do what you are asking for, I just did it. Also, now you can compile from any of the files and it will work.

1
  • Sorry, but as You may see from the previous answer - this does not help.
    – Fortaz
    Oct 7, 2013 at 16:59

You must log in to answer this question.

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