Custom format file and subfiles
I want to use a custom format file to speed up my compilation. However this doesn't play together with the subfiles package.
Consider the following minimal example:
preamble.tex
documentclass[a4paper,12pt]{article}
usepackage{subfiles}
usepackage{lipsum}
%%further packages and custom commands
From this I can create a custom format using
pdflatex -ini -jobname="preamble" "&pdflatex preamble.texdump"
The other files are:
main.tex
begin{document}
Here are the contents of my subfile:
subfile{sub}
end{document}
Compiling this works via:
pdflatex -fmt preamble main.tex
sub.tex
documentclass[main]{subfiles}
begin{document}
lipsum
end{document}
However compiling this via
pdflatex -fmt preamble sub.tex
doesn't work and gives the error message:
! LaTeX Error: Two documentclass or documentstyle commands.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.1 documentclass[main]{
subfiles}
?
How can I make it work?
format-files subfiles performance
add a comment |
I want to use a custom format file to speed up my compilation. However this doesn't play together with the subfiles package.
Consider the following minimal example:
preamble.tex
documentclass[a4paper,12pt]{article}
usepackage{subfiles}
usepackage{lipsum}
%%further packages and custom commands
From this I can create a custom format using
pdflatex -ini -jobname="preamble" "&pdflatex preamble.texdump"
The other files are:
main.tex
begin{document}
Here are the contents of my subfile:
subfile{sub}
end{document}
Compiling this works via:
pdflatex -fmt preamble main.tex
sub.tex
documentclass[main]{subfiles}
begin{document}
lipsum
end{document}
However compiling this via
pdflatex -fmt preamble sub.tex
doesn't work and gives the error message:
! LaTeX Error: Two documentclass or documentstyle commands.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.1 documentclass[main]{
subfiles}
?
How can I make it work?
format-files subfiles performance
Maybe you can get it to work with the standalone package instead of subfiles? With the standalone package, preambles of included files are ignored
– Grimler
Mar 24 '16 at 20:39
But how can I make a standalone file use the same preamble as the main file?
– student
Mar 25 '16 at 0:17
add a comment |
I want to use a custom format file to speed up my compilation. However this doesn't play together with the subfiles package.
Consider the following minimal example:
preamble.tex
documentclass[a4paper,12pt]{article}
usepackage{subfiles}
usepackage{lipsum}
%%further packages and custom commands
From this I can create a custom format using
pdflatex -ini -jobname="preamble" "&pdflatex preamble.texdump"
The other files are:
main.tex
begin{document}
Here are the contents of my subfile:
subfile{sub}
end{document}
Compiling this works via:
pdflatex -fmt preamble main.tex
sub.tex
documentclass[main]{subfiles}
begin{document}
lipsum
end{document}
However compiling this via
pdflatex -fmt preamble sub.tex
doesn't work and gives the error message:
! LaTeX Error: Two documentclass or documentstyle commands.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.1 documentclass[main]{
subfiles}
?
How can I make it work?
format-files subfiles performance
I want to use a custom format file to speed up my compilation. However this doesn't play together with the subfiles package.
Consider the following minimal example:
preamble.tex
documentclass[a4paper,12pt]{article}
usepackage{subfiles}
usepackage{lipsum}
%%further packages and custom commands
From this I can create a custom format using
pdflatex -ini -jobname="preamble" "&pdflatex preamble.texdump"
The other files are:
main.tex
begin{document}
Here are the contents of my subfile:
subfile{sub}
end{document}
Compiling this works via:
pdflatex -fmt preamble main.tex
sub.tex
documentclass[main]{subfiles}
begin{document}
lipsum
end{document}
However compiling this via
pdflatex -fmt preamble sub.tex
doesn't work and gives the error message:
! LaTeX Error: Two documentclass or documentstyle commands.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.1 documentclass[main]{
subfiles}
?
How can I make it work?
format-files subfiles performance
format-files subfiles performance
edited Mar 19 '16 at 12:11
student
asked Mar 19 '16 at 11:52
studentstudent
12.3k2397174
12.3k2397174
Maybe you can get it to work with the standalone package instead of subfiles? With the standalone package, preambles of included files are ignored
– Grimler
Mar 24 '16 at 20:39
But how can I make a standalone file use the same preamble as the main file?
– student
Mar 25 '16 at 0:17
add a comment |
Maybe you can get it to work with the standalone package instead of subfiles? With the standalone package, preambles of included files are ignored
– Grimler
Mar 24 '16 at 20:39
But how can I make a standalone file use the same preamble as the main file?
– student
Mar 25 '16 at 0:17
Maybe you can get it to work with the standalone package instead of subfiles? With the standalone package, preambles of included files are ignored
– Grimler
Mar 24 '16 at 20:39
Maybe you can get it to work with the standalone package instead of subfiles? With the standalone package, preambles of included files are ignored
– Grimler
Mar 24 '16 at 20:39
But how can I make a standalone file use the same preamble as the main file?
– student
Mar 25 '16 at 0:17
But how can I make a standalone file use the same preamble as the main file?
– student
Mar 25 '16 at 0:17
add a comment |
3 Answers
3
active
oldest
votes
pdflatex -fmt preamble sub.tex
The error is self-explanatory: In this way you provide two documentclass
, that is not the same that left to the subfile
class to be replaced by the (non-existent in this case) document class of main.tex
. This is the same that compile a single file with this wrong code:
documentclass[a4paper,12pt]{article}
usepackage{subfiles}
usepackage{lipsum}
documentclass[main]{subfiles}
documentclass{article}
begin{document}
lipsum[1]
end{document}
The possible solutions:
1) Left documentclass
in main.tex
. Then, the problem will be that in preamble.tex
there are usepackage
commands that must be used after the documentclass
(of main.tex), not before. Fortunately this command can be replaced by RequirePackage
. So, this preamble.tex
produce a working preamble.fmt
RequirePackage{subfiles}
RequirePackage{lipsum}
%%further packages and custom commands
The main.tex
should be then:
documentclass[a4paper,12pt]{article} %
begin{document}
Here are the contents of my subfile:
subfile{sub}
end{document}
2) Alternatively, in case of trouble with some code, resign to a non-precompiled preamble (fused in main.tex
or included with input{preamble}
).
3) If the precompiled preamble is indispensable (=noticeable seep up), in case of trouble I guess that should be possible use a mix of both approaches (that is, a pre-compiled/pre-document preamble plus the conventional non-precompiled/post-document preamble with the problematic code). However, this look like the typical situations in which I regret ignore the KISS principle ("Keep it simple, stupid").
add a comment |
Try adding the docmute package to the preamble format file instead of subfiles, and a regular article class in the sub file. the problem is that latex only allows one documentclass per document, and you are adding a second in the subfile; docmute redefines the documentclass command and the document environment, so that the preambles of the included files are ignored. so, using docmute and standard include should solve the problem
Isn't this too generic to be an answer?
– egreg
Mar 24 '16 at 23:25
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– egreg
Mar 24 '16 at 23:26
I have added some explanation to my answer.
– erreka
Mar 25 '16 at 1:36
add a comment |
I would do it with two format files, one with the subfiles
document class and one with article
. As the error message says, you can't have two documentclass
statements in a single file — having one in your custom format file counts!
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f299812%2fcustom-format-file-and-subfiles%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
pdflatex -fmt preamble sub.tex
The error is self-explanatory: In this way you provide two documentclass
, that is not the same that left to the subfile
class to be replaced by the (non-existent in this case) document class of main.tex
. This is the same that compile a single file with this wrong code:
documentclass[a4paper,12pt]{article}
usepackage{subfiles}
usepackage{lipsum}
documentclass[main]{subfiles}
documentclass{article}
begin{document}
lipsum[1]
end{document}
The possible solutions:
1) Left documentclass
in main.tex
. Then, the problem will be that in preamble.tex
there are usepackage
commands that must be used after the documentclass
(of main.tex), not before. Fortunately this command can be replaced by RequirePackage
. So, this preamble.tex
produce a working preamble.fmt
RequirePackage{subfiles}
RequirePackage{lipsum}
%%further packages and custom commands
The main.tex
should be then:
documentclass[a4paper,12pt]{article} %
begin{document}
Here are the contents of my subfile:
subfile{sub}
end{document}
2) Alternatively, in case of trouble with some code, resign to a non-precompiled preamble (fused in main.tex
or included with input{preamble}
).
3) If the precompiled preamble is indispensable (=noticeable seep up), in case of trouble I guess that should be possible use a mix of both approaches (that is, a pre-compiled/pre-document preamble plus the conventional non-precompiled/post-document preamble with the problematic code). However, this look like the typical situations in which I regret ignore the KISS principle ("Keep it simple, stupid").
add a comment |
pdflatex -fmt preamble sub.tex
The error is self-explanatory: In this way you provide two documentclass
, that is not the same that left to the subfile
class to be replaced by the (non-existent in this case) document class of main.tex
. This is the same that compile a single file with this wrong code:
documentclass[a4paper,12pt]{article}
usepackage{subfiles}
usepackage{lipsum}
documentclass[main]{subfiles}
documentclass{article}
begin{document}
lipsum[1]
end{document}
The possible solutions:
1) Left documentclass
in main.tex
. Then, the problem will be that in preamble.tex
there are usepackage
commands that must be used after the documentclass
(of main.tex), not before. Fortunately this command can be replaced by RequirePackage
. So, this preamble.tex
produce a working preamble.fmt
RequirePackage{subfiles}
RequirePackage{lipsum}
%%further packages and custom commands
The main.tex
should be then:
documentclass[a4paper,12pt]{article} %
begin{document}
Here are the contents of my subfile:
subfile{sub}
end{document}
2) Alternatively, in case of trouble with some code, resign to a non-precompiled preamble (fused in main.tex
or included with input{preamble}
).
3) If the precompiled preamble is indispensable (=noticeable seep up), in case of trouble I guess that should be possible use a mix of both approaches (that is, a pre-compiled/pre-document preamble plus the conventional non-precompiled/post-document preamble with the problematic code). However, this look like the typical situations in which I regret ignore the KISS principle ("Keep it simple, stupid").
add a comment |
pdflatex -fmt preamble sub.tex
The error is self-explanatory: In this way you provide two documentclass
, that is not the same that left to the subfile
class to be replaced by the (non-existent in this case) document class of main.tex
. This is the same that compile a single file with this wrong code:
documentclass[a4paper,12pt]{article}
usepackage{subfiles}
usepackage{lipsum}
documentclass[main]{subfiles}
documentclass{article}
begin{document}
lipsum[1]
end{document}
The possible solutions:
1) Left documentclass
in main.tex
. Then, the problem will be that in preamble.tex
there are usepackage
commands that must be used after the documentclass
(of main.tex), not before. Fortunately this command can be replaced by RequirePackage
. So, this preamble.tex
produce a working preamble.fmt
RequirePackage{subfiles}
RequirePackage{lipsum}
%%further packages and custom commands
The main.tex
should be then:
documentclass[a4paper,12pt]{article} %
begin{document}
Here are the contents of my subfile:
subfile{sub}
end{document}
2) Alternatively, in case of trouble with some code, resign to a non-precompiled preamble (fused in main.tex
or included with input{preamble}
).
3) If the precompiled preamble is indispensable (=noticeable seep up), in case of trouble I guess that should be possible use a mix of both approaches (that is, a pre-compiled/pre-document preamble plus the conventional non-precompiled/post-document preamble with the problematic code). However, this look like the typical situations in which I regret ignore the KISS principle ("Keep it simple, stupid").
pdflatex -fmt preamble sub.tex
The error is self-explanatory: In this way you provide two documentclass
, that is not the same that left to the subfile
class to be replaced by the (non-existent in this case) document class of main.tex
. This is the same that compile a single file with this wrong code:
documentclass[a4paper,12pt]{article}
usepackage{subfiles}
usepackage{lipsum}
documentclass[main]{subfiles}
documentclass{article}
begin{document}
lipsum[1]
end{document}
The possible solutions:
1) Left documentclass
in main.tex
. Then, the problem will be that in preamble.tex
there are usepackage
commands that must be used after the documentclass
(of main.tex), not before. Fortunately this command can be replaced by RequirePackage
. So, this preamble.tex
produce a working preamble.fmt
RequirePackage{subfiles}
RequirePackage{lipsum}
%%further packages and custom commands
The main.tex
should be then:
documentclass[a4paper,12pt]{article} %
begin{document}
Here are the contents of my subfile:
subfile{sub}
end{document}
2) Alternatively, in case of trouble with some code, resign to a non-precompiled preamble (fused in main.tex
or included with input{preamble}
).
3) If the precompiled preamble is indispensable (=noticeable seep up), in case of trouble I guess that should be possible use a mix of both approaches (that is, a pre-compiled/pre-document preamble plus the conventional non-precompiled/post-document preamble with the problematic code). However, this look like the typical situations in which I regret ignore the KISS principle ("Keep it simple, stupid").
edited Mar 28 '16 at 7:33
answered Mar 28 '16 at 6:59
FranFran
51.8k6114175
51.8k6114175
add a comment |
add a comment |
Try adding the docmute package to the preamble format file instead of subfiles, and a regular article class in the sub file. the problem is that latex only allows one documentclass per document, and you are adding a second in the subfile; docmute redefines the documentclass command and the document environment, so that the preambles of the included files are ignored. so, using docmute and standard include should solve the problem
Isn't this too generic to be an answer?
– egreg
Mar 24 '16 at 23:25
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– egreg
Mar 24 '16 at 23:26
I have added some explanation to my answer.
– erreka
Mar 25 '16 at 1:36
add a comment |
Try adding the docmute package to the preamble format file instead of subfiles, and a regular article class in the sub file. the problem is that latex only allows one documentclass per document, and you are adding a second in the subfile; docmute redefines the documentclass command and the document environment, so that the preambles of the included files are ignored. so, using docmute and standard include should solve the problem
Isn't this too generic to be an answer?
– egreg
Mar 24 '16 at 23:25
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– egreg
Mar 24 '16 at 23:26
I have added some explanation to my answer.
– erreka
Mar 25 '16 at 1:36
add a comment |
Try adding the docmute package to the preamble format file instead of subfiles, and a regular article class in the sub file. the problem is that latex only allows one documentclass per document, and you are adding a second in the subfile; docmute redefines the documentclass command and the document environment, so that the preambles of the included files are ignored. so, using docmute and standard include should solve the problem
Try adding the docmute package to the preamble format file instead of subfiles, and a regular article class in the sub file. the problem is that latex only allows one documentclass per document, and you are adding a second in the subfile; docmute redefines the documentclass command and the document environment, so that the preambles of the included files are ignored. so, using docmute and standard include should solve the problem
edited Mar 25 '16 at 1:33
answered Mar 24 '16 at 22:57
errekaerreka
3,345928
3,345928
Isn't this too generic to be an answer?
– egreg
Mar 24 '16 at 23:25
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– egreg
Mar 24 '16 at 23:26
I have added some explanation to my answer.
– erreka
Mar 25 '16 at 1:36
add a comment |
Isn't this too generic to be an answer?
– egreg
Mar 24 '16 at 23:25
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– egreg
Mar 24 '16 at 23:26
I have added some explanation to my answer.
– erreka
Mar 25 '16 at 1:36
Isn't this too generic to be an answer?
– egreg
Mar 24 '16 at 23:25
Isn't this too generic to be an answer?
– egreg
Mar 24 '16 at 23:25
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– egreg
Mar 24 '16 at 23:26
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– egreg
Mar 24 '16 at 23:26
I have added some explanation to my answer.
– erreka
Mar 25 '16 at 1:36
I have added some explanation to my answer.
– erreka
Mar 25 '16 at 1:36
add a comment |
I would do it with two format files, one with the subfiles
document class and one with article
. As the error message says, you can't have two documentclass
statements in a single file — having one in your custom format file counts!
add a comment |
I would do it with two format files, one with the subfiles
document class and one with article
. As the error message says, you can't have two documentclass
statements in a single file — having one in your custom format file counts!
add a comment |
I would do it with two format files, one with the subfiles
document class and one with article
. As the error message says, you can't have two documentclass
statements in a single file — having one in your custom format file counts!
I would do it with two format files, one with the subfiles
document class and one with article
. As the error message says, you can't have two documentclass
statements in a single file — having one in your custom format file counts!
answered Mar 24 '16 at 20:08
kadalkadal
835
835
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f299812%2fcustom-format-file-and-subfiles%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Maybe you can get it to work with the standalone package instead of subfiles? With the standalone package, preambles of included files are ignored
– Grimler
Mar 24 '16 at 20:39
But how can I make a standalone file use the same preamble as the main file?
– student
Mar 25 '16 at 0:17