gsalzer / subfiles

class and package for multi-file projects in LaTeX
LaTeX Project Public License v1.3c
25 stars 1 forks source link

references between subfiles #9

Closed ndvanforeest closed 3 years ago

ndvanforeest commented 3 years ago

Thanks to your new command ifSubfilesClassLoaded referencing between subfiles becomes easy.

gsalzer commented 3 years ago

Are you sure that \ifSubfilesClassLoaded is needed? The new version of subfiles skips the preamble of subfiles when loading them via \subfile. Try to add the \externaldocument to the preamble, without \ifSubfilesClassLoaded. Does it still work then?

ndvanforeest commented 3 years ago

When I used \externaldocument this morning, the main file would not compile. Then I updated subfiles because I read in the documentation the \ifSubfilesClassLoaded switch, and this seemed precisely what I needed. Hence, I did not test without it. But now I did, and it works as you say: I don't need the switch for things to work.

Do you want me to update my pull request?

Thanks for a great package.

On Fri, 25 Sep 2020 at 20:01, gsalzer notifications@github.com wrote:

Are you sure that \ifSubfilesClassLoaded is needed? The new version of subfiles skips the preamble of subfiles when loading them via \subfile. Try to add the \externaldocument to the preamble, without \ifSubfilesClassLoaded. Does it still work then?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gsalzer/subfiles/pull/9#issuecomment-699071813, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM266IX7QMXRZGTGM2NGFDSHTLH5ANCNFSM4RZMUPDA .

gsalzer commented 3 years ago

"Do you want me to update my pull request?"

Thanks, but not really necessary, I will merge the request and do the remaining changes myself. But before, I'm looking for a plausible use case and try to construct a test. In which context do you use xr? The problem I encounter: If the aux file of the main document is used, then one gets duplicate labels for the labels in the subfile.

What is your use case that avoids duplicate labels?

ndvanforeest commented 3 years ago

OK, great.

I use emacs with auctex and reftex. Reftex apparently knows about subfiles, so when I let reftex generate a label, it prevents double labels.

When working on a subfile, I got tired of reading [??} in the pdf for the references to other subfiles. With xr and importing the main document as an external document in the subfile, the references to other subfiles are now ok.

If you find it useful, I can send you a MWE for my use case. Here is another demand for something similar: https://tex.stackexchange.com/questions/390952/cross-references-and-subfiles

On Sun, 27 Sep 2020 at 11:58, gsalzer notifications@github.com wrote:

"Do you want me to update my pull request?"

Thanks, but not really necessary, I will merge the request and do the remaining changes myself. But before, I'm looking for a plausible use case and try to construct a test. In which context do you use xr? The problem I encounter: If the aux file of the main document is used, then one gets duplicate labels for the labels in the subfile.

What is your use case that avoids duplicate labels?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gsalzer/subfiles/pull/9#issuecomment-699613602, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM266OXFEGFXXALGBOEPE3SH4EFBANCNFSM4RZMUPDA .

gsalzer commented 3 years ago

@ndvanforeest I have merged your input and rephrased it a bit. Please check the recipe for cross-referencing for your use case and let me know in case it does not work as described. Thanks for your contribution!

ndvanforeest commented 3 years ago

Your example is a bit harder than what I use. I don't use the M- in front of the references, and I find it a bit cumbersome to type. Here is a basic setup of what I do. For me it works painless. But, I use subfiles only for fast testing of sections of bigger documents, so perhaps my use case is much simpler than how other people use it.

========main.tex=========== \documentclass{article} \usepackage{subfiles} \usepackage{xr} \title{The main file}

\begin{document} \maketitle

This is the main file.

Now comes the text of sub1.tex.

\subfile{sub1}

Now comes the text of sub2.tex.

\subfile{sub2}

\end{document}

========sub1.tex====== \documentclass[main]{subfiles} \externaldocument{main}

\begin{document} This file sub1.tex.

Here is a reference to~Eq.\ref{eq:1} from file sub2.tex. And here is another equation: \begin{equation}\label{eq:2} b = 3. \end{equation}

\end{document}

=====sub2.tex========= \documentclass[main]{subfiles} \externaldocument{main}

\begin{document} This file sub1.tex.

Here is a reference to~Eq.\ref{eq:2} from file sub1.tex.

Here is a labeled equation. \begin{equation} \label{eq:1} a = b. \end{equation}

\end{document}

On Sat, 3 Oct 2020 at 23:50, gsalzer notifications@github.com wrote:

@ndvanforeest https://github.com/ndvanforeest I have merged your input and rephrased it a bit. Please check the recipe for cross-referencing for your use case and let me know in case it does not work as described. Thanks for your contribution!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gsalzer/subfiles/pull/9#issuecomment-703168992, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM266L5K7Z4J76NGGQRDZLSI6MEFANCNFSM4RZMUPDA .

gsalzer commented 3 years ago

Your example generates warnings: multiply-defined labels. When typesetting sub1.tex, then the files sub1.aux and main.aux (included via external document) contain the same label, but with different numbers. It depends on the internal processing, which numbers become visible in the document. It may be the ones intended, or the other, wrong ones. A properly typeset document shouldn't show the line LaTeX Warning: There were multiply-defined labels. in the log file. The only solution I found that avoids that is the one with the prefix M-.

ndvanforeest commented 3 years ago

Sure, but for my purpose these warnings on the subfiles is no problem. As long as the main file compiles without errors, I am fine.

On Mon, 5 Oct 2020 at 21:01, gsalzer notifications@github.com wrote:

Your example generates warnings: multiply-defined labels. When typesetting sub1.tex, then the files sub1.aux and main.aux (included via external document) contain the same label, but with different numbers. It depends on the internal processing, which numbers become visible in the document. It may be the ones intended, or the other, wrong ones. A properly typeset document shouldn't show the line LaTeX Warning: There were multiply-defined labels. in the log file. The only solution I found that avoids that is the one with the prefix M-.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gsalzer/subfiles/pull/9#issuecomment-703827251, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM266OHM3JWLK5SPRZOAM3SJIJZXANCNFSM4RZMUPDA .

gsalzer commented 3 years ago

Well, at least in the documentation, I want to be more cautious. There are at least two potential problems with the don't-care-approach. First, if the duplicate-label-warning is always there, then you will miss other, really duplicate labels. Second, the warning is indeed meaningful: The same label appear with different page and number information, and it depends on the internal processing which numbers will be displayed. So your approach may work with one document, but in another the wrong numbers may be displayed if the aux files are processed in a different order.

In any case, thanks for your contribution! It is a good idea to have recipes and use cases in the docs.

ndvanforeest commented 3 years ago

Your arguments make a lot is sense to me.

Once again, thanks for your great package. It is one of those packages that make latex a power tool.

Sent from my iPad

On 6 Oct 2020, at 11:39, gsalzer notifications@github.com wrote:

 Well, at least in the documentation, I want to be more cautious. There are at least two potential problems with the don't-care-approach. First, if the duplicate-label-warning is always there, then you will miss other, really duplicate labels. Second, the warning is indeed meaningful: The same label appear with different page and number information, and it depends on the internal processing which numbers will be displayed. So your approach may work with one document, but in another the wrong numbers may be displayed if the aux files are processed in a different order.

In any case, thanks for your contribution! It is a good idea to have recipes and use cases in the docs.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.