-
Notifications
You must be signed in to change notification settings - Fork 389
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Multi-file project with subfile #155
Comments
Hi! First, I've never heard about the subfile package. It seems like a nice idea, although it does introduce some complexities that I am not quite sure if I want to introduce to Regarding your first question: Please see %! TEX root = my-main.tex in order to set the main file. This should always work. For your second question, the answer is currently no. The question is interesting though, as it could be a nice functionality to compile the current file outside of context of the main file. However, I don't see a simple way to do , and I am not quite sure that I want to complicate the code in order to support this. Much because there does exist a "standard" way to solve the problem through the The same applies to your third question: I would be willing to discuss ideas for new features and enhancements, but I want to stress that I one of the main benefits of |
I should have written that I know about '%! TEX root'. The reason I'm asking about the other way is that I have around 40 files in a project and adding this line to every file seems inelegant. Before when using LatexBox I was using autocommand to assign the necessary variable. Moreover, every file has already a '\documentclass[my-main.tex]{subfiles}' which can be reused for this purpose. Since vimtex needs a master file for the correct completions and already parses the file for the string '%!..' I think it would be quite essential to determine the main file by looking for documentclass as well. That was the easiest part. I appreciate your desire to keep the project simple. I also currently do not see a simple way to support something like two main files. The compilation issue can be nevertheless ignored when using other tools for compilation, like 'vim-dispatcher'. It would be pity to loose vimtex's ability for forward/backward search. The easiest way to still be able to use it is to add an optional argument for VimtexView command with the desired 'pdf' file. In this case everyone could make his own mappings. |
Could you explain in more detail how you did this with LaTeX-Box? Then I could perhaps add a similar functonality to Regarding the possibility to add a custom However, for the compilation issue, I think I vote against it for now, since as you say this can be solved with other plugins. However, if you do have an idea for a simple implementation of this, then don't hesitate to open a feature request! In the following I would be happy if we could keep the topic of this issue on the detection of the main file. |
For the project I have a local .vimrc file with the following line: au FileType tex let b:main_tex_file='main.tex' So for each project opened in a current session the main file is set automatically. |
Thanks for the feedback. |
No problem. I'll look into this later today or this week. |
This should do it, I think. I''ve named the variable |
It works, thanks! Sorry for bothering you with it , are you also going to add the pattern for '\documentclass[main.tex]{subfiles}' to the check of the main documents, or you consider it excessive? |
No bother! As you already know, I've today used the assumption that there is only one So my proposal: I change the main file pattern from One more note about the proposal: It is not as of now possible to use multiple main files, so you can not change from the subfile main to the project main interactively. However, it should be possible to create a custom function that |
It seems that there is some confusion concerning the proposals (: My proposal was to add '\documentclass[main.tex]{subfiles}' as a pattern in the same place, where you check for '%! TeX root:main.tex'. So Concerning your proposal to switch to main file detection from |
Just in case, the subfile document has both |
Added parsing of main file from `\documentclass[main.tex]{subfiles}`.
Ah, I see. So first, based on your last comment it seems unnecessary to change the regexp as I proposed (no need to fix something that is not broken). Now back to your proposal: I've tried to implement what you suggested. Could you test and comment? I've done some simple testing, and it looks good on my end. One thing: Do you think it is enough to parse only the first five lines (as I'm doing now), or should I increase this threshold? Also, I chose not to add a new option. It doesn't seem necessary in my opinion. |
It works as expected for flat projects, where included files are located in the same folder as main. For the project with tree structure, where included files are located in subfolders it fails. As far as I can understand the code it tests if file is located in the same folder as the current one, while the file is actually located in Concerning the number of lines. Personally I've never seen a project where \documentclass would be located not on a first line. I'm not much familiar with '%!' options though. So I guess that 5 lines should be enough. |
Yes, it worth noting that subfiles seem not to understand '../../' main files so all the activity is done in the project root. |
That is interesting. Does
The lines that construct the main file path are: if candidate[0] !=# '/'
let candidate = expand('%:h') . '/' . candidate
endif
let main = fnamemodify(candidate, ':p') If |
The situation is quite primitive. For the project you describe you have latex sub/sub.tex
or
latexmk sub/sub.tex This actually make sense. In a projects like this there may be additional included and sty files located in the root folder. The only way latex will find them is to call it from root. I can imagine no simple way for latex to do it if called in As for me, I usually start gvim in a root folder with servername specified and |
Hmm. I've been searching for documentation that specifies things, and I found this. The example is similar to the one I've presented above, and it uses the same format as I've assumed with, that is, \documentclass[../main.tex]{subfiles} To me this seems the only sensible thing. When |
Indeed, now it works in some cases. Nevertheless what I've written before is based on my own experience - I've failed to use relative paths when I've started using subfiles. See the following example below. You need to create For this project you can:
And you can not:
Only if you remove
\begin{filecontents}{sub/rel.tex}
\documentclass[../test.tex]{subfiles}
\begin{document}
relative
\end{document}
\end{filecontents}
\begin{filecontents}{sub/abs.tex}
\documentclass[test.tex]{subfiles}
\begin{document}
absolute
\end{document}
\end{filecontents}
\begin{filecontents}{test.sty}
\end{filecontents}
\documentclass{report}
\usepackage{subfiles}
\usepackage{test}
\begin{document}
Contents:
\subfile{sub/rel.tex}
\subfile{sub/abs.tex}
\end{document} |
I tested your example. And since the subfiles package itself seem to specifiy that the main file reference should be relative to the working directory, it seems you are right that I should respect the working directory. In the latest commit, I've implemented this. It will first try relative to the current file, then it tries relative to working directory. Let me know if it works as it should. |
It works as expected. Thanks! |
Great! |
Hi, I'm used to do multi-file projects, based on subfile package. In other words each included file has its own begin/end document environment and can be compiled independently. The compilation and the compiled files happen in the root directory, even if the file itself is located in subfolder. There fore I have several questions.
Thank you in advance. Vimtex is amazing and fast.
The text was updated successfully, but these errors were encountered: