Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inputting the preamble and the documentclass #1612

Closed
PatrickJosh opened this issue Oct 12, 2020 · 4 comments · Fixed by #1617
Closed

Inputting the preamble and the documentclass #1612

PatrickJosh opened this issue Oct 12, 2020 · 4 comments · Fixed by #1617
Assignees
Labels
bug Deficiencies in TeXiFy behaviour.

Comments

@PatrickJosh
Copy link

Hey,
I have a question regarding the \input and \documentclass commands. My use case is that I have a preamble.tex file which contains all \usepackage commands and the \documentclass and several other files which input this preamble.tex. Each of these files is a separate root document.

Here is a minimal example:

preamble.tex:

\documentclass{article}
\usepackage{amsmath}

other_file.tex:

\input{preamble.tex}
\begin{document}
    \begin{align}
    x &= y
    \end{align}
\end{document}

In this example, TeXiFy tells me that the amsmath package is required to use the align environment, although \usepackage{amsmath} is specified in the preamble.tex and it compiles with no errors.

The only way I have seen to make this setup work with TeXiFy is to remove the \documentclass command in the preamble.tex file and move it to each of the other files, in this example to other_file.tex. Is there a way to use a setup like this without having to move the \documentclass command to each of the files?

I tried to make use of the magic %! root command as well but with no success.

I'm using

  • TeXiFy version 0.7
  • PyCharm 2020.2.2 (Community Edition), Build #PC-202.7319.64, built on September 16, 2020
  • Ubuntu 20.04.1
@PatrickJosh PatrickJosh added the untriaged Issue type still needs to be triaged or verified. label Oct 12, 2020
@PHPirates
Copy link
Collaborator

You are right, the magic comment seems broken. Besides that, do you think it is more common to have the document environment in the main file than the documentclass? Perhaps we should take that as default for finding the main file, instead of the documentclass command. Downside of changing it, is that it might break things for a lot of people.
I think we also look at run configurations, but unfortunately that isn't watertight as well: you can have run configs for subfiles.

Anyway, we should somehow make it clear in the UI that when certain inspections don't work as expected, a magic comment might solve it (because now that's relatively hard to find out that that could solve it).

@PHPirates PHPirates added bug Deficiencies in TeXiFy behaviour. and removed untriaged Issue type still needs to be triaged or verified. labels Oct 13, 2020
@PatrickJosh
Copy link
Author

PatrickJosh commented Oct 13, 2020

Yes, I think this way is more common. I would never input the document environment, I would rather include/input the preamble and maybe chapter files if it is a large document and I think—for the people I know and the templates I have gotten so far at my university—that this is the default.
Maybe there could be a switch in the settings to choose whether you like to detect the master file by \documentclass or by the document environment.

Yeah, this does not sound easy to implement. Maybe it could start with a hint that you could use the %! root if \documentclass is not in this file but you input some other files. That is a very specific use case but it could be helpful for some people.

Moreover, I do not know how I would use the magic comment in my specific situation. I cannot use it in the preamble.tex because I use this file as preamble for may files. I could only use it in the other_file.tex, but there it has to be something like %! root = ./other_file.tex because it cannot point to the preamble.tex. Otherwise the preamble.tex would be compiled (if I understand the comment correctly) and that's not what I want.

@slideclimb slideclimb self-assigned this Oct 14, 2020
@slideclimb
Copy link
Collaborator

Just to give you our reasoning behind using the \documentclass to determine the root file, so you know where we're coming from:

When it comes to the structure of a source file, we try to follow the structure as given in The LaTeX Companion (Second Edition). This means that the \documentclass is not part of the preamble:

Commands placed between \documentclass and \begin{document} are in the so-called document preamble.

However, you can specify the documentclass in your custom 'preamble' as well, but then you would turn it into a documentclass definition itself. This means that you convert it to a class file custom.cls which is inputted in your main/root file using \documentclass{custom}. Hence the \documentclass would always be in the root file.

That being said, when not following these conventions your file will compile just fine, and it should definitely not cause the errors/warnings it currently does. It should probably be an inspection (which you can turn off) complaining that your \documentclass is in a different file than your document environment.

@slideclimb slideclimb mentioned this issue Oct 15, 2020
1 task
@PatrickJosh
Copy link
Author

Ok, that makes sense! Thanks for explaining.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Deficiencies in TeXiFy behaviour.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants