Is it possible to write a class file that loops over the documentbody?
What I would like to achieve is a repeat.cls such that I could write a .tex file
documentclass{repeat}
begin{document}
foobar
end{document}
and then the document would contain 'foobar' a certain number of times.
Is this possible? I tried to combine loop
or foreach
with the AtBeginDocument
and AtEndDocument
, but from what I know now, that approach cannot work as TeX would never really "see" the end{document}
.
tex-core documentclass-writing
add a comment |
What I would like to achieve is a repeat.cls such that I could write a .tex file
documentclass{repeat}
begin{document}
foobar
end{document}
and then the document would contain 'foobar' a certain number of times.
Is this possible? I tried to combine loop
or foreach
with the AtBeginDocument
and AtEndDocument
, but from what I know now, that approach cannot work as TeX would never really "see" the end{document}
.
tex-core documentclass-writing
Probably not that way. You'd need a macro which would scan the text, but this macro can't "exit" the class file. You'd need a commandmyWeirdLoop
after thedocumentclass
. It would still mess up you document, mainly anything that contains catcode changes. What do you want to achieve exactly?
– Phelype Oleinik
Dec 11 '18 at 18:22
1
@PhelypeOleinik could we save the meaning of document (begin and end) and the combine with environ. Plus a macro in the preamble to specify the number of repetitions.
– daleif
Dec 11 '18 at 18:29
1
@daleif Ooh, with egeg's answer I understood it. Sometimes I need a drawing to understand things :P
– Phelype Oleinik
Dec 11 '18 at 18:38
add a comment |
What I would like to achieve is a repeat.cls such that I could write a .tex file
documentclass{repeat}
begin{document}
foobar
end{document}
and then the document would contain 'foobar' a certain number of times.
Is this possible? I tried to combine loop
or foreach
with the AtBeginDocument
and AtEndDocument
, but from what I know now, that approach cannot work as TeX would never really "see" the end{document}
.
tex-core documentclass-writing
What I would like to achieve is a repeat.cls such that I could write a .tex file
documentclass{repeat}
begin{document}
foobar
end{document}
and then the document would contain 'foobar' a certain number of times.
Is this possible? I tried to combine loop
or foreach
with the AtBeginDocument
and AtEndDocument
, but from what I know now, that approach cannot work as TeX would never really "see" the end{document}
.
tex-core documentclass-writing
tex-core documentclass-writing
edited Dec 11 '18 at 18:26
Stefan Pinnow
19.4k83175
19.4k83175
asked Dec 11 '18 at 18:17
CFrei
132
132
Probably not that way. You'd need a macro which would scan the text, but this macro can't "exit" the class file. You'd need a commandmyWeirdLoop
after thedocumentclass
. It would still mess up you document, mainly anything that contains catcode changes. What do you want to achieve exactly?
– Phelype Oleinik
Dec 11 '18 at 18:22
1
@PhelypeOleinik could we save the meaning of document (begin and end) and the combine with environ. Plus a macro in the preamble to specify the number of repetitions.
– daleif
Dec 11 '18 at 18:29
1
@daleif Ooh, with egeg's answer I understood it. Sometimes I need a drawing to understand things :P
– Phelype Oleinik
Dec 11 '18 at 18:38
add a comment |
Probably not that way. You'd need a macro which would scan the text, but this macro can't "exit" the class file. You'd need a commandmyWeirdLoop
after thedocumentclass
. It would still mess up you document, mainly anything that contains catcode changes. What do you want to achieve exactly?
– Phelype Oleinik
Dec 11 '18 at 18:22
1
@PhelypeOleinik could we save the meaning of document (begin and end) and the combine with environ. Plus a macro in the preamble to specify the number of repetitions.
– daleif
Dec 11 '18 at 18:29
1
@daleif Ooh, with egeg's answer I understood it. Sometimes I need a drawing to understand things :P
– Phelype Oleinik
Dec 11 '18 at 18:38
Probably not that way. You'd need a macro which would scan the text, but this macro can't "exit" the class file. You'd need a command
myWeirdLoop
after the documentclass
. It would still mess up you document, mainly anything that contains catcode changes. What do you want to achieve exactly?– Phelype Oleinik
Dec 11 '18 at 18:22
Probably not that way. You'd need a macro which would scan the text, but this macro can't "exit" the class file. You'd need a command
myWeirdLoop
after the documentclass
. It would still mess up you document, mainly anything that contains catcode changes. What do you want to achieve exactly?– Phelype Oleinik
Dec 11 '18 at 18:22
1
1
@PhelypeOleinik could we save the meaning of document (begin and end) and the combine with environ. Plus a macro in the preamble to specify the number of repetitions.
– daleif
Dec 11 '18 at 18:29
@PhelypeOleinik could we save the meaning of document (begin and end) and the combine with environ. Plus a macro in the preamble to specify the number of repetitions.
– daleif
Dec 11 '18 at 18:29
1
1
@daleif Ooh, with egeg's answer I understood it. Sometimes I need a drawing to understand things :P
– Phelype Oleinik
Dec 11 '18 at 18:38
@daleif Ooh, with egeg's answer I understood it. Sometimes I need a drawing to understand things :P
– Phelype Oleinik
Dec 11 '18 at 18:38
add a comment |
1 Answer
1
active
oldest
votes
Proof of concept follows. Don't do it at home.
repeat.cls
ProvidesClass{repeat}
defrepetitions{5} % default
DeclareOption*{edefrepetitions{CurrentOption}}
ProcessOptionsrelax
LoadClass{article}
RequirePackage{environ,xparse}
letlatexdocumentdocument
letendlatexdocumentenddocument
ExplSyntaxOn
RenewEnviron{document}{
tl_gset_eq:NN g_tmpa_tl BODY
latexdocument
prg_replicate:nn { repetitions } { g_tmpa_tl par }
endlatexdocument
}
ExplSyntaxOff
test.tex
documentclass[20]{repeat}
begin{document}
foobar
end{document}
Output
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%2f464366%2fis-it-possible-to-write-a-class-file-that-loops-over-the-documentbody%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Proof of concept follows. Don't do it at home.
repeat.cls
ProvidesClass{repeat}
defrepetitions{5} % default
DeclareOption*{edefrepetitions{CurrentOption}}
ProcessOptionsrelax
LoadClass{article}
RequirePackage{environ,xparse}
letlatexdocumentdocument
letendlatexdocumentenddocument
ExplSyntaxOn
RenewEnviron{document}{
tl_gset_eq:NN g_tmpa_tl BODY
latexdocument
prg_replicate:nn { repetitions } { g_tmpa_tl par }
endlatexdocument
}
ExplSyntaxOff
test.tex
documentclass[20]{repeat}
begin{document}
foobar
end{document}
Output
add a comment |
Proof of concept follows. Don't do it at home.
repeat.cls
ProvidesClass{repeat}
defrepetitions{5} % default
DeclareOption*{edefrepetitions{CurrentOption}}
ProcessOptionsrelax
LoadClass{article}
RequirePackage{environ,xparse}
letlatexdocumentdocument
letendlatexdocumentenddocument
ExplSyntaxOn
RenewEnviron{document}{
tl_gset_eq:NN g_tmpa_tl BODY
latexdocument
prg_replicate:nn { repetitions } { g_tmpa_tl par }
endlatexdocument
}
ExplSyntaxOff
test.tex
documentclass[20]{repeat}
begin{document}
foobar
end{document}
Output
add a comment |
Proof of concept follows. Don't do it at home.
repeat.cls
ProvidesClass{repeat}
defrepetitions{5} % default
DeclareOption*{edefrepetitions{CurrentOption}}
ProcessOptionsrelax
LoadClass{article}
RequirePackage{environ,xparse}
letlatexdocumentdocument
letendlatexdocumentenddocument
ExplSyntaxOn
RenewEnviron{document}{
tl_gset_eq:NN g_tmpa_tl BODY
latexdocument
prg_replicate:nn { repetitions } { g_tmpa_tl par }
endlatexdocument
}
ExplSyntaxOff
test.tex
documentclass[20]{repeat}
begin{document}
foobar
end{document}
Output
Proof of concept follows. Don't do it at home.
repeat.cls
ProvidesClass{repeat}
defrepetitions{5} % default
DeclareOption*{edefrepetitions{CurrentOption}}
ProcessOptionsrelax
LoadClass{article}
RequirePackage{environ,xparse}
letlatexdocumentdocument
letendlatexdocumentenddocument
ExplSyntaxOn
RenewEnviron{document}{
tl_gset_eq:NN g_tmpa_tl BODY
latexdocument
prg_replicate:nn { repetitions } { g_tmpa_tl par }
endlatexdocument
}
ExplSyntaxOff
test.tex
documentclass[20]{repeat}
begin{document}
foobar
end{document}
Output
answered Dec 11 '18 at 18:28
egreg
709k8618823165
709k8618823165
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f464366%2fis-it-possible-to-write-a-class-file-that-loops-over-the-documentbody%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
Probably not that way. You'd need a macro which would scan the text, but this macro can't "exit" the class file. You'd need a command
myWeirdLoop
after thedocumentclass
. It would still mess up you document, mainly anything that contains catcode changes. What do you want to achieve exactly?– Phelype Oleinik
Dec 11 '18 at 18:22
1
@PhelypeOleinik could we save the meaning of document (begin and end) and the combine with environ. Plus a macro in the preamble to specify the number of repetitions.
– daleif
Dec 11 '18 at 18:29
1
@daleif Ooh, with egeg's answer I understood it. Sometimes I need a drawing to understand things :P
– Phelype Oleinik
Dec 11 '18 at 18:38