How to automatically create multiple versions of a document with different paper sizes & reflecting this...












1















I am using the moderncv class to prepare my resume for applying to jobs in the US (where the standard paper size is letter), and in UK (where the standard paper size is A4).



Here is a MWE file called main.tex.



% some preamble stuff before `documentclass` line
% blah blah (preamble)
% more blah blah (preamble)

documentclass[11pt,a4paper,sans]{moderncv} % <----- paper size is set here.

% a lot more preamble lines after `documentclass` line
moderncvstyle{classic}
usepackage{graphicx}

firstname{John}
familyname{Doe}

address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{example-image-a}


begin{document}
makecvtitle
end{document}


As shown in the MWE, some of my custom preamble precedes the documentclass line, whilst some others comes after it.



I am using latexmk to compile the document with lualatex. How can I maintain just a single tex source and automatically build two different versions of the PDF document each appropriately named Resume_A4paper.pdf and Resume_letterpaper.pdf? I am happy to use any directlua magic and/or external tools to facilitate this.



Rationale



With the present content, I have manually checked that the page layout is okay for both A4/letter sizes. I just want to automate this process for future minor tweaks (modifying one or two bullet points in the whole CV to tailor to each job description). It would be tedious to manually produce 2 different versions for each type of job/industry I am applying for.










share|improve this question

























  • In my view a CV should be carefully checked for layout changes, so automatically changing paper size is quite a huge step to take. But why don't you simply set up a one-line file, read its content before documentclass and then pass it as option?

    – TeXnician
    Feb 18 at 15:01











  • @TeXnician I have manually checked the layout with the present content, and the page layout is okay for both A4/letter sizes. I just want to automate this process for any minor tweaks (modifying one or two bullet points in the whole CV to tailor to each job description). Sorry, but I do not understand your suggestion in the 2nd half of your comment.

    – Krishna
    Feb 18 at 15:04













  • Why don't put your personal data in another file to input and create two main files with paper size in name and compile both?

    – Sigur
    Feb 18 at 15:11











  • @Sigur Ok. Can latexmk be used here? Also, is this amenable to the suitable automatic naming of the output PDFs?

    – Krishna
    Feb 18 at 15:13






  • 1





    You say that the content fits on both A4 and letterpaper. If it looks reasonable on both then I don't see any need to produce two different PDF files.

    – Peter Wilson
    Feb 18 at 18:45
















1















I am using the moderncv class to prepare my resume for applying to jobs in the US (where the standard paper size is letter), and in UK (where the standard paper size is A4).



Here is a MWE file called main.tex.



% some preamble stuff before `documentclass` line
% blah blah (preamble)
% more blah blah (preamble)

documentclass[11pt,a4paper,sans]{moderncv} % <----- paper size is set here.

% a lot more preamble lines after `documentclass` line
moderncvstyle{classic}
usepackage{graphicx}

firstname{John}
familyname{Doe}

address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{example-image-a}


begin{document}
makecvtitle
end{document}


As shown in the MWE, some of my custom preamble precedes the documentclass line, whilst some others comes after it.



I am using latexmk to compile the document with lualatex. How can I maintain just a single tex source and automatically build two different versions of the PDF document each appropriately named Resume_A4paper.pdf and Resume_letterpaper.pdf? I am happy to use any directlua magic and/or external tools to facilitate this.



Rationale



With the present content, I have manually checked that the page layout is okay for both A4/letter sizes. I just want to automate this process for future minor tweaks (modifying one or two bullet points in the whole CV to tailor to each job description). It would be tedious to manually produce 2 different versions for each type of job/industry I am applying for.










share|improve this question

























  • In my view a CV should be carefully checked for layout changes, so automatically changing paper size is quite a huge step to take. But why don't you simply set up a one-line file, read its content before documentclass and then pass it as option?

    – TeXnician
    Feb 18 at 15:01











  • @TeXnician I have manually checked the layout with the present content, and the page layout is okay for both A4/letter sizes. I just want to automate this process for any minor tweaks (modifying one or two bullet points in the whole CV to tailor to each job description). Sorry, but I do not understand your suggestion in the 2nd half of your comment.

    – Krishna
    Feb 18 at 15:04













  • Why don't put your personal data in another file to input and create two main files with paper size in name and compile both?

    – Sigur
    Feb 18 at 15:11











  • @Sigur Ok. Can latexmk be used here? Also, is this amenable to the suitable automatic naming of the output PDFs?

    – Krishna
    Feb 18 at 15:13






  • 1





    You say that the content fits on both A4 and letterpaper. If it looks reasonable on both then I don't see any need to produce two different PDF files.

    – Peter Wilson
    Feb 18 at 18:45














1












1








1








I am using the moderncv class to prepare my resume for applying to jobs in the US (where the standard paper size is letter), and in UK (where the standard paper size is A4).



Here is a MWE file called main.tex.



% some preamble stuff before `documentclass` line
% blah blah (preamble)
% more blah blah (preamble)

documentclass[11pt,a4paper,sans]{moderncv} % <----- paper size is set here.

% a lot more preamble lines after `documentclass` line
moderncvstyle{classic}
usepackage{graphicx}

firstname{John}
familyname{Doe}

address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{example-image-a}


begin{document}
makecvtitle
end{document}


As shown in the MWE, some of my custom preamble precedes the documentclass line, whilst some others comes after it.



I am using latexmk to compile the document with lualatex. How can I maintain just a single tex source and automatically build two different versions of the PDF document each appropriately named Resume_A4paper.pdf and Resume_letterpaper.pdf? I am happy to use any directlua magic and/or external tools to facilitate this.



Rationale



With the present content, I have manually checked that the page layout is okay for both A4/letter sizes. I just want to automate this process for future minor tweaks (modifying one or two bullet points in the whole CV to tailor to each job description). It would be tedious to manually produce 2 different versions for each type of job/industry I am applying for.










share|improve this question
















I am using the moderncv class to prepare my resume for applying to jobs in the US (where the standard paper size is letter), and in UK (where the standard paper size is A4).



Here is a MWE file called main.tex.



% some preamble stuff before `documentclass` line
% blah blah (preamble)
% more blah blah (preamble)

documentclass[11pt,a4paper,sans]{moderncv} % <----- paper size is set here.

% a lot more preamble lines after `documentclass` line
moderncvstyle{classic}
usepackage{graphicx}

firstname{John}
familyname{Doe}

address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{example-image-a}


begin{document}
makecvtitle
end{document}


As shown in the MWE, some of my custom preamble precedes the documentclass line, whilst some others comes after it.



I am using latexmk to compile the document with lualatex. How can I maintain just a single tex source and automatically build two different versions of the PDF document each appropriately named Resume_A4paper.pdf and Resume_letterpaper.pdf? I am happy to use any directlua magic and/or external tools to facilitate this.



Rationale



With the present content, I have manually checked that the page layout is okay for both A4/letter sizes. I just want to automate this process for future minor tweaks (modifying one or two bullet points in the whole CV to tailor to each job description). It would be tedious to manually produce 2 different versions for each type of job/industry I am applying for.







moderncv automation latexmk shell-escape






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 18 at 15:06







Krishna

















asked Feb 18 at 14:42









KrishnaKrishna

1,151620




1,151620













  • In my view a CV should be carefully checked for layout changes, so automatically changing paper size is quite a huge step to take. But why don't you simply set up a one-line file, read its content before documentclass and then pass it as option?

    – TeXnician
    Feb 18 at 15:01











  • @TeXnician I have manually checked the layout with the present content, and the page layout is okay for both A4/letter sizes. I just want to automate this process for any minor tweaks (modifying one or two bullet points in the whole CV to tailor to each job description). Sorry, but I do not understand your suggestion in the 2nd half of your comment.

    – Krishna
    Feb 18 at 15:04













  • Why don't put your personal data in another file to input and create two main files with paper size in name and compile both?

    – Sigur
    Feb 18 at 15:11











  • @Sigur Ok. Can latexmk be used here? Also, is this amenable to the suitable automatic naming of the output PDFs?

    – Krishna
    Feb 18 at 15:13






  • 1





    You say that the content fits on both A4 and letterpaper. If it looks reasonable on both then I don't see any need to produce two different PDF files.

    – Peter Wilson
    Feb 18 at 18:45



















  • In my view a CV should be carefully checked for layout changes, so automatically changing paper size is quite a huge step to take. But why don't you simply set up a one-line file, read its content before documentclass and then pass it as option?

    – TeXnician
    Feb 18 at 15:01











  • @TeXnician I have manually checked the layout with the present content, and the page layout is okay for both A4/letter sizes. I just want to automate this process for any minor tweaks (modifying one or two bullet points in the whole CV to tailor to each job description). Sorry, but I do not understand your suggestion in the 2nd half of your comment.

    – Krishna
    Feb 18 at 15:04













  • Why don't put your personal data in another file to input and create two main files with paper size in name and compile both?

    – Sigur
    Feb 18 at 15:11











  • @Sigur Ok. Can latexmk be used here? Also, is this amenable to the suitable automatic naming of the output PDFs?

    – Krishna
    Feb 18 at 15:13






  • 1





    You say that the content fits on both A4 and letterpaper. If it looks reasonable on both then I don't see any need to produce two different PDF files.

    – Peter Wilson
    Feb 18 at 18:45

















In my view a CV should be carefully checked for layout changes, so automatically changing paper size is quite a huge step to take. But why don't you simply set up a one-line file, read its content before documentclass and then pass it as option?

– TeXnician
Feb 18 at 15:01





In my view a CV should be carefully checked for layout changes, so automatically changing paper size is quite a huge step to take. But why don't you simply set up a one-line file, read its content before documentclass and then pass it as option?

– TeXnician
Feb 18 at 15:01













@TeXnician I have manually checked the layout with the present content, and the page layout is okay for both A4/letter sizes. I just want to automate this process for any minor tweaks (modifying one or two bullet points in the whole CV to tailor to each job description). Sorry, but I do not understand your suggestion in the 2nd half of your comment.

– Krishna
Feb 18 at 15:04







@TeXnician I have manually checked the layout with the present content, and the page layout is okay for both A4/letter sizes. I just want to automate this process for any minor tweaks (modifying one or two bullet points in the whole CV to tailor to each job description). Sorry, but I do not understand your suggestion in the 2nd half of your comment.

– Krishna
Feb 18 at 15:04















Why don't put your personal data in another file to input and create two main files with paper size in name and compile both?

– Sigur
Feb 18 at 15:11





Why don't put your personal data in another file to input and create two main files with paper size in name and compile both?

– Sigur
Feb 18 at 15:11













@Sigur Ok. Can latexmk be used here? Also, is this amenable to the suitable automatic naming of the output PDFs?

– Krishna
Feb 18 at 15:13





@Sigur Ok. Can latexmk be used here? Also, is this amenable to the suitable automatic naming of the output PDFs?

– Krishna
Feb 18 at 15:13




1




1





You say that the content fits on both A4 and letterpaper. If it looks reasonable on both then I don't see any need to produce two different PDF files.

– Peter Wilson
Feb 18 at 18:45





You say that the content fits on both A4 and letterpaper. If it looks reasonable on both then I don't see any need to produce two different PDF files.

– Peter Wilson
Feb 18 at 18:45










1 Answer
1






active

oldest

votes


















2














When on my system I save the following example as test.tex and on the shell (via chdir or cd or whatever) change the active directory to the directory where test.tex is stored, and then compile test.tex by calling latexmk from the shell/command-line via



latexmk -cd -gg -pdflatex="lualatex --shell-escape %O %S" -pdf -dvi- -ps- test.tex


(maybe on your platform you need --enable-write18 instead of --shell-escape)



, then during the first lualatex-run initiated by latexmk, where aux-files don't exist in the beginning, another latexmk-run is initiated where the -jobname-option is used for attaching the phrase -letterpaper to the current expansion of jobname.



In any case it is checked whether the expansion of the jobname-primitive contains the phrase -letterpaper.



If so, the option "letterpaper" is passed to the documentclass.



If not so, the option "a4paper" is passed to the documentclass.



As a result you have one latexmk-run on test.tex which exactly once initiates another latexmk-run on test.tex with -jobname="test-letterpaper".



In the end you get test.pdf which is a4paper and test-letterpaper.pdf which is letterpaper.



If you wish, you can provide the -jobname-option on the shell/command-line also and e.g., do



latexmk -cd -gg -jobname="test-a4paper" -pdflatex="lualatex --shell-escape %O %S" -pdf -dvi- -ps- test.tex


(maybe on your platform you need --enable-write18 instead of --shell-escape)



in order to get test-a4paper.pdf and test-letterpaper.pdf.



makeatletter
RequirePackage{shellesc}% more recent releases of LuaTeX don't provide
% write18 any more. This package makes sure
% under such LuaTeX write18 is emulated by
% calls to directlua.
newcommandCheckWhetherNull[1]{%
ifrelaxdetokenize{#1}relax
expandafter@firstoftwoelseexpandafter@secondoftwofi
}%
newcommandletterpaperphrase{-letterpaper}@onelevel@sanitizeletterpaperphrase
newcommandAfourpaperphrase{-a4paper}@onelevel@sanitizeAfourpaperphrase
%
newcommandgobbletoletterpaperphrase{}%
expandafterlongexpandafterdef
expandaftergobbletoletterpaperphraseexpandafter#expandafter1letterpaperphrase{}%
%
newcommandgobbletoAfourpaperphrase{}%
expandafterlongexpandafterdef
expandaftergobbletoAfourpaperphraseexpandafter#expandafter1Afourpaperphrase{}%
%
newcommandkeepBeforeAfourpaperphrase{}%
expandafterlongexpandafterdef
expandafterkeepBeforeAfourpaperphrase
expandafter#expandafter1Afourpaperphrase#2relax{#1}%
%
newcommandCheckWhetherJobNameHasLetterpaperphrase{}%
expandafterdef
expandafterCheckWhetherJobNameHasLetterpaperphrase
expandafter{%
romannumeral0expandafterCheckWhetherNullexpandafter{%
romannumeral0@firstofone{expandafterexpandafterexpandafter} %
expandaftergobbletoletterpaperphrase
romannumeral0@firstofone{expandafterexpandafterexpandafter} %
expandafterjobname
letterpaperphrase
}%
{ @secondoftwo}%
{ @firstoftwo}%
}%
newcommandCheckWhetherJobNameHasAfourpaperphrase{}%
expandafterdef
expandafterCheckWhetherJobNameHasAfourpaperphrase
expandafter{%
romannumeral0expandafterCheckWhetherNullexpandafter{%
romannumeral0@firstofone{expandafterexpandafterexpandafter} %
expandaftergobbletoAfourpaperphrase
romannumeral0@firstofone{expandafterexpandafterexpandafter} %
expandafterjobname
Afourpaperphrase
}%
{ @secondoftwo}%
{ @firstoftwo}%
}%
CheckWhetherJobNameHasLetterpaperphrase{%
PassOptionsToClass{letterpaper}{moderncv}%
}{%
PassOptionsToClass{a4paper}{moderncv}%
}%
IfFileExists{jobname.tex}{%
newcommandmyinfile{jobname.tex}%
}{%
newcommandmyinfile{%
CheckWhetherJobNameHasAfourpaperphrase
{expandafterkeepBeforeAfourpaperphrasejobnamerelax}%
{jobname}.tex%
}%
}%
newcommandcreateletterdocument{%
ShellEscape{%
latexmk -cd
-gg
-jobname="CheckWhetherJobNameHasAfourpaperphrase
{expandafterkeepBeforeAfourpaperphrasejobnamerelax}%
{jobname}%
letterpaperphrase"
-pdflatex="lualatex @percentchar O @percentchar S"
-pdf -dvi- -ps-
myinfile
}%
}%
AtBeginDocument{%
begingroup
immediatewrite@mainaux{stringglobalstringletstringcreateletterdocument=stringempty}%
endgroup
CheckWhetherJobNameHasLetterpaperphrase{}{createletterdocument}%
}%
makeatother

% some preamble stuff before `documentclass` line
% blah blah (preamble)
% more blah blah (preamble)

documentclass[11pt,sans]{moderncv} % <----- paper size is _not_
% set here but is set via PassOptionsToClass.

makeatletter
@ifundefined{pdfpagewidth}{}{pdfpagewidth=paperwidth}%
@ifundefined{pdfpageheight}{}{pdfpageheight=paperheight}%
@ifundefined{pagewidth}{}{pagewidth=paperwidth}%
@ifundefined{pageheight}{}{pageheight=paperheight}%
makeatother

% a lot more preamble lines after `documentclass` line
moderncvstyle{classic}
usepackage{graphicx}

firstname{John}
familyname{Doe}

address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{example-image-a}


begin{document}
makecvtitle
end{document}





share|improve this answer

























    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475503%2fhow-to-automatically-create-multiple-versions-of-a-document-with-different-paper%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









    2














    When on my system I save the following example as test.tex and on the shell (via chdir or cd or whatever) change the active directory to the directory where test.tex is stored, and then compile test.tex by calling latexmk from the shell/command-line via



    latexmk -cd -gg -pdflatex="lualatex --shell-escape %O %S" -pdf -dvi- -ps- test.tex


    (maybe on your platform you need --enable-write18 instead of --shell-escape)



    , then during the first lualatex-run initiated by latexmk, where aux-files don't exist in the beginning, another latexmk-run is initiated where the -jobname-option is used for attaching the phrase -letterpaper to the current expansion of jobname.



    In any case it is checked whether the expansion of the jobname-primitive contains the phrase -letterpaper.



    If so, the option "letterpaper" is passed to the documentclass.



    If not so, the option "a4paper" is passed to the documentclass.



    As a result you have one latexmk-run on test.tex which exactly once initiates another latexmk-run on test.tex with -jobname="test-letterpaper".



    In the end you get test.pdf which is a4paper and test-letterpaper.pdf which is letterpaper.



    If you wish, you can provide the -jobname-option on the shell/command-line also and e.g., do



    latexmk -cd -gg -jobname="test-a4paper" -pdflatex="lualatex --shell-escape %O %S" -pdf -dvi- -ps- test.tex


    (maybe on your platform you need --enable-write18 instead of --shell-escape)



    in order to get test-a4paper.pdf and test-letterpaper.pdf.



    makeatletter
    RequirePackage{shellesc}% more recent releases of LuaTeX don't provide
    % write18 any more. This package makes sure
    % under such LuaTeX write18 is emulated by
    % calls to directlua.
    newcommandCheckWhetherNull[1]{%
    ifrelaxdetokenize{#1}relax
    expandafter@firstoftwoelseexpandafter@secondoftwofi
    }%
    newcommandletterpaperphrase{-letterpaper}@onelevel@sanitizeletterpaperphrase
    newcommandAfourpaperphrase{-a4paper}@onelevel@sanitizeAfourpaperphrase
    %
    newcommandgobbletoletterpaperphrase{}%
    expandafterlongexpandafterdef
    expandaftergobbletoletterpaperphraseexpandafter#expandafter1letterpaperphrase{}%
    %
    newcommandgobbletoAfourpaperphrase{}%
    expandafterlongexpandafterdef
    expandaftergobbletoAfourpaperphraseexpandafter#expandafter1Afourpaperphrase{}%
    %
    newcommandkeepBeforeAfourpaperphrase{}%
    expandafterlongexpandafterdef
    expandafterkeepBeforeAfourpaperphrase
    expandafter#expandafter1Afourpaperphrase#2relax{#1}%
    %
    newcommandCheckWhetherJobNameHasLetterpaperphrase{}%
    expandafterdef
    expandafterCheckWhetherJobNameHasLetterpaperphrase
    expandafter{%
    romannumeral0expandafterCheckWhetherNullexpandafter{%
    romannumeral0@firstofone{expandafterexpandafterexpandafter} %
    expandaftergobbletoletterpaperphrase
    romannumeral0@firstofone{expandafterexpandafterexpandafter} %
    expandafterjobname
    letterpaperphrase
    }%
    { @secondoftwo}%
    { @firstoftwo}%
    }%
    newcommandCheckWhetherJobNameHasAfourpaperphrase{}%
    expandafterdef
    expandafterCheckWhetherJobNameHasAfourpaperphrase
    expandafter{%
    romannumeral0expandafterCheckWhetherNullexpandafter{%
    romannumeral0@firstofone{expandafterexpandafterexpandafter} %
    expandaftergobbletoAfourpaperphrase
    romannumeral0@firstofone{expandafterexpandafterexpandafter} %
    expandafterjobname
    Afourpaperphrase
    }%
    { @secondoftwo}%
    { @firstoftwo}%
    }%
    CheckWhetherJobNameHasLetterpaperphrase{%
    PassOptionsToClass{letterpaper}{moderncv}%
    }{%
    PassOptionsToClass{a4paper}{moderncv}%
    }%
    IfFileExists{jobname.tex}{%
    newcommandmyinfile{jobname.tex}%
    }{%
    newcommandmyinfile{%
    CheckWhetherJobNameHasAfourpaperphrase
    {expandafterkeepBeforeAfourpaperphrasejobnamerelax}%
    {jobname}.tex%
    }%
    }%
    newcommandcreateletterdocument{%
    ShellEscape{%
    latexmk -cd
    -gg
    -jobname="CheckWhetherJobNameHasAfourpaperphrase
    {expandafterkeepBeforeAfourpaperphrasejobnamerelax}%
    {jobname}%
    letterpaperphrase"
    -pdflatex="lualatex @percentchar O @percentchar S"
    -pdf -dvi- -ps-
    myinfile
    }%
    }%
    AtBeginDocument{%
    begingroup
    immediatewrite@mainaux{stringglobalstringletstringcreateletterdocument=stringempty}%
    endgroup
    CheckWhetherJobNameHasLetterpaperphrase{}{createletterdocument}%
    }%
    makeatother

    % some preamble stuff before `documentclass` line
    % blah blah (preamble)
    % more blah blah (preamble)

    documentclass[11pt,sans]{moderncv} % <----- paper size is _not_
    % set here but is set via PassOptionsToClass.

    makeatletter
    @ifundefined{pdfpagewidth}{}{pdfpagewidth=paperwidth}%
    @ifundefined{pdfpageheight}{}{pdfpageheight=paperheight}%
    @ifundefined{pagewidth}{}{pagewidth=paperwidth}%
    @ifundefined{pageheight}{}{pageheight=paperheight}%
    makeatother

    % a lot more preamble lines after `documentclass` line
    moderncvstyle{classic}
    usepackage{graphicx}

    firstname{John}
    familyname{Doe}

    address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
    phone[mobile]{123 456 7890}
    email{someone@xyz.com}
    photo[64pt][0.5pt]{example-image-a}


    begin{document}
    makecvtitle
    end{document}





    share|improve this answer






























      2














      When on my system I save the following example as test.tex and on the shell (via chdir or cd or whatever) change the active directory to the directory where test.tex is stored, and then compile test.tex by calling latexmk from the shell/command-line via



      latexmk -cd -gg -pdflatex="lualatex --shell-escape %O %S" -pdf -dvi- -ps- test.tex


      (maybe on your platform you need --enable-write18 instead of --shell-escape)



      , then during the first lualatex-run initiated by latexmk, where aux-files don't exist in the beginning, another latexmk-run is initiated where the -jobname-option is used for attaching the phrase -letterpaper to the current expansion of jobname.



      In any case it is checked whether the expansion of the jobname-primitive contains the phrase -letterpaper.



      If so, the option "letterpaper" is passed to the documentclass.



      If not so, the option "a4paper" is passed to the documentclass.



      As a result you have one latexmk-run on test.tex which exactly once initiates another latexmk-run on test.tex with -jobname="test-letterpaper".



      In the end you get test.pdf which is a4paper and test-letterpaper.pdf which is letterpaper.



      If you wish, you can provide the -jobname-option on the shell/command-line also and e.g., do



      latexmk -cd -gg -jobname="test-a4paper" -pdflatex="lualatex --shell-escape %O %S" -pdf -dvi- -ps- test.tex


      (maybe on your platform you need --enable-write18 instead of --shell-escape)



      in order to get test-a4paper.pdf and test-letterpaper.pdf.



      makeatletter
      RequirePackage{shellesc}% more recent releases of LuaTeX don't provide
      % write18 any more. This package makes sure
      % under such LuaTeX write18 is emulated by
      % calls to directlua.
      newcommandCheckWhetherNull[1]{%
      ifrelaxdetokenize{#1}relax
      expandafter@firstoftwoelseexpandafter@secondoftwofi
      }%
      newcommandletterpaperphrase{-letterpaper}@onelevel@sanitizeletterpaperphrase
      newcommandAfourpaperphrase{-a4paper}@onelevel@sanitizeAfourpaperphrase
      %
      newcommandgobbletoletterpaperphrase{}%
      expandafterlongexpandafterdef
      expandaftergobbletoletterpaperphraseexpandafter#expandafter1letterpaperphrase{}%
      %
      newcommandgobbletoAfourpaperphrase{}%
      expandafterlongexpandafterdef
      expandaftergobbletoAfourpaperphraseexpandafter#expandafter1Afourpaperphrase{}%
      %
      newcommandkeepBeforeAfourpaperphrase{}%
      expandafterlongexpandafterdef
      expandafterkeepBeforeAfourpaperphrase
      expandafter#expandafter1Afourpaperphrase#2relax{#1}%
      %
      newcommandCheckWhetherJobNameHasLetterpaperphrase{}%
      expandafterdef
      expandafterCheckWhetherJobNameHasLetterpaperphrase
      expandafter{%
      romannumeral0expandafterCheckWhetherNullexpandafter{%
      romannumeral0@firstofone{expandafterexpandafterexpandafter} %
      expandaftergobbletoletterpaperphrase
      romannumeral0@firstofone{expandafterexpandafterexpandafter} %
      expandafterjobname
      letterpaperphrase
      }%
      { @secondoftwo}%
      { @firstoftwo}%
      }%
      newcommandCheckWhetherJobNameHasAfourpaperphrase{}%
      expandafterdef
      expandafterCheckWhetherJobNameHasAfourpaperphrase
      expandafter{%
      romannumeral0expandafterCheckWhetherNullexpandafter{%
      romannumeral0@firstofone{expandafterexpandafterexpandafter} %
      expandaftergobbletoAfourpaperphrase
      romannumeral0@firstofone{expandafterexpandafterexpandafter} %
      expandafterjobname
      Afourpaperphrase
      }%
      { @secondoftwo}%
      { @firstoftwo}%
      }%
      CheckWhetherJobNameHasLetterpaperphrase{%
      PassOptionsToClass{letterpaper}{moderncv}%
      }{%
      PassOptionsToClass{a4paper}{moderncv}%
      }%
      IfFileExists{jobname.tex}{%
      newcommandmyinfile{jobname.tex}%
      }{%
      newcommandmyinfile{%
      CheckWhetherJobNameHasAfourpaperphrase
      {expandafterkeepBeforeAfourpaperphrasejobnamerelax}%
      {jobname}.tex%
      }%
      }%
      newcommandcreateletterdocument{%
      ShellEscape{%
      latexmk -cd
      -gg
      -jobname="CheckWhetherJobNameHasAfourpaperphrase
      {expandafterkeepBeforeAfourpaperphrasejobnamerelax}%
      {jobname}%
      letterpaperphrase"
      -pdflatex="lualatex @percentchar O @percentchar S"
      -pdf -dvi- -ps-
      myinfile
      }%
      }%
      AtBeginDocument{%
      begingroup
      immediatewrite@mainaux{stringglobalstringletstringcreateletterdocument=stringempty}%
      endgroup
      CheckWhetherJobNameHasLetterpaperphrase{}{createletterdocument}%
      }%
      makeatother

      % some preamble stuff before `documentclass` line
      % blah blah (preamble)
      % more blah blah (preamble)

      documentclass[11pt,sans]{moderncv} % <----- paper size is _not_
      % set here but is set via PassOptionsToClass.

      makeatletter
      @ifundefined{pdfpagewidth}{}{pdfpagewidth=paperwidth}%
      @ifundefined{pdfpageheight}{}{pdfpageheight=paperheight}%
      @ifundefined{pagewidth}{}{pagewidth=paperwidth}%
      @ifundefined{pageheight}{}{pageheight=paperheight}%
      makeatother

      % a lot more preamble lines after `documentclass` line
      moderncvstyle{classic}
      usepackage{graphicx}

      firstname{John}
      familyname{Doe}

      address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
      phone[mobile]{123 456 7890}
      email{someone@xyz.com}
      photo[64pt][0.5pt]{example-image-a}


      begin{document}
      makecvtitle
      end{document}





      share|improve this answer




























        2












        2








        2







        When on my system I save the following example as test.tex and on the shell (via chdir or cd or whatever) change the active directory to the directory where test.tex is stored, and then compile test.tex by calling latexmk from the shell/command-line via



        latexmk -cd -gg -pdflatex="lualatex --shell-escape %O %S" -pdf -dvi- -ps- test.tex


        (maybe on your platform you need --enable-write18 instead of --shell-escape)



        , then during the first lualatex-run initiated by latexmk, where aux-files don't exist in the beginning, another latexmk-run is initiated where the -jobname-option is used for attaching the phrase -letterpaper to the current expansion of jobname.



        In any case it is checked whether the expansion of the jobname-primitive contains the phrase -letterpaper.



        If so, the option "letterpaper" is passed to the documentclass.



        If not so, the option "a4paper" is passed to the documentclass.



        As a result you have one latexmk-run on test.tex which exactly once initiates another latexmk-run on test.tex with -jobname="test-letterpaper".



        In the end you get test.pdf which is a4paper and test-letterpaper.pdf which is letterpaper.



        If you wish, you can provide the -jobname-option on the shell/command-line also and e.g., do



        latexmk -cd -gg -jobname="test-a4paper" -pdflatex="lualatex --shell-escape %O %S" -pdf -dvi- -ps- test.tex


        (maybe on your platform you need --enable-write18 instead of --shell-escape)



        in order to get test-a4paper.pdf and test-letterpaper.pdf.



        makeatletter
        RequirePackage{shellesc}% more recent releases of LuaTeX don't provide
        % write18 any more. This package makes sure
        % under such LuaTeX write18 is emulated by
        % calls to directlua.
        newcommandCheckWhetherNull[1]{%
        ifrelaxdetokenize{#1}relax
        expandafter@firstoftwoelseexpandafter@secondoftwofi
        }%
        newcommandletterpaperphrase{-letterpaper}@onelevel@sanitizeletterpaperphrase
        newcommandAfourpaperphrase{-a4paper}@onelevel@sanitizeAfourpaperphrase
        %
        newcommandgobbletoletterpaperphrase{}%
        expandafterlongexpandafterdef
        expandaftergobbletoletterpaperphraseexpandafter#expandafter1letterpaperphrase{}%
        %
        newcommandgobbletoAfourpaperphrase{}%
        expandafterlongexpandafterdef
        expandaftergobbletoAfourpaperphraseexpandafter#expandafter1Afourpaperphrase{}%
        %
        newcommandkeepBeforeAfourpaperphrase{}%
        expandafterlongexpandafterdef
        expandafterkeepBeforeAfourpaperphrase
        expandafter#expandafter1Afourpaperphrase#2relax{#1}%
        %
        newcommandCheckWhetherJobNameHasLetterpaperphrase{}%
        expandafterdef
        expandafterCheckWhetherJobNameHasLetterpaperphrase
        expandafter{%
        romannumeral0expandafterCheckWhetherNullexpandafter{%
        romannumeral0@firstofone{expandafterexpandafterexpandafter} %
        expandaftergobbletoletterpaperphrase
        romannumeral0@firstofone{expandafterexpandafterexpandafter} %
        expandafterjobname
        letterpaperphrase
        }%
        { @secondoftwo}%
        { @firstoftwo}%
        }%
        newcommandCheckWhetherJobNameHasAfourpaperphrase{}%
        expandafterdef
        expandafterCheckWhetherJobNameHasAfourpaperphrase
        expandafter{%
        romannumeral0expandafterCheckWhetherNullexpandafter{%
        romannumeral0@firstofone{expandafterexpandafterexpandafter} %
        expandaftergobbletoAfourpaperphrase
        romannumeral0@firstofone{expandafterexpandafterexpandafter} %
        expandafterjobname
        Afourpaperphrase
        }%
        { @secondoftwo}%
        { @firstoftwo}%
        }%
        CheckWhetherJobNameHasLetterpaperphrase{%
        PassOptionsToClass{letterpaper}{moderncv}%
        }{%
        PassOptionsToClass{a4paper}{moderncv}%
        }%
        IfFileExists{jobname.tex}{%
        newcommandmyinfile{jobname.tex}%
        }{%
        newcommandmyinfile{%
        CheckWhetherJobNameHasAfourpaperphrase
        {expandafterkeepBeforeAfourpaperphrasejobnamerelax}%
        {jobname}.tex%
        }%
        }%
        newcommandcreateletterdocument{%
        ShellEscape{%
        latexmk -cd
        -gg
        -jobname="CheckWhetherJobNameHasAfourpaperphrase
        {expandafterkeepBeforeAfourpaperphrasejobnamerelax}%
        {jobname}%
        letterpaperphrase"
        -pdflatex="lualatex @percentchar O @percentchar S"
        -pdf -dvi- -ps-
        myinfile
        }%
        }%
        AtBeginDocument{%
        begingroup
        immediatewrite@mainaux{stringglobalstringletstringcreateletterdocument=stringempty}%
        endgroup
        CheckWhetherJobNameHasLetterpaperphrase{}{createletterdocument}%
        }%
        makeatother

        % some preamble stuff before `documentclass` line
        % blah blah (preamble)
        % more blah blah (preamble)

        documentclass[11pt,sans]{moderncv} % <----- paper size is _not_
        % set here but is set via PassOptionsToClass.

        makeatletter
        @ifundefined{pdfpagewidth}{}{pdfpagewidth=paperwidth}%
        @ifundefined{pdfpageheight}{}{pdfpageheight=paperheight}%
        @ifundefined{pagewidth}{}{pagewidth=paperwidth}%
        @ifundefined{pageheight}{}{pageheight=paperheight}%
        makeatother

        % a lot more preamble lines after `documentclass` line
        moderncvstyle{classic}
        usepackage{graphicx}

        firstname{John}
        familyname{Doe}

        address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
        phone[mobile]{123 456 7890}
        email{someone@xyz.com}
        photo[64pt][0.5pt]{example-image-a}


        begin{document}
        makecvtitle
        end{document}





        share|improve this answer















        When on my system I save the following example as test.tex and on the shell (via chdir or cd or whatever) change the active directory to the directory where test.tex is stored, and then compile test.tex by calling latexmk from the shell/command-line via



        latexmk -cd -gg -pdflatex="lualatex --shell-escape %O %S" -pdf -dvi- -ps- test.tex


        (maybe on your platform you need --enable-write18 instead of --shell-escape)



        , then during the first lualatex-run initiated by latexmk, where aux-files don't exist in the beginning, another latexmk-run is initiated where the -jobname-option is used for attaching the phrase -letterpaper to the current expansion of jobname.



        In any case it is checked whether the expansion of the jobname-primitive contains the phrase -letterpaper.



        If so, the option "letterpaper" is passed to the documentclass.



        If not so, the option "a4paper" is passed to the documentclass.



        As a result you have one latexmk-run on test.tex which exactly once initiates another latexmk-run on test.tex with -jobname="test-letterpaper".



        In the end you get test.pdf which is a4paper and test-letterpaper.pdf which is letterpaper.



        If you wish, you can provide the -jobname-option on the shell/command-line also and e.g., do



        latexmk -cd -gg -jobname="test-a4paper" -pdflatex="lualatex --shell-escape %O %S" -pdf -dvi- -ps- test.tex


        (maybe on your platform you need --enable-write18 instead of --shell-escape)



        in order to get test-a4paper.pdf and test-letterpaper.pdf.



        makeatletter
        RequirePackage{shellesc}% more recent releases of LuaTeX don't provide
        % write18 any more. This package makes sure
        % under such LuaTeX write18 is emulated by
        % calls to directlua.
        newcommandCheckWhetherNull[1]{%
        ifrelaxdetokenize{#1}relax
        expandafter@firstoftwoelseexpandafter@secondoftwofi
        }%
        newcommandletterpaperphrase{-letterpaper}@onelevel@sanitizeletterpaperphrase
        newcommandAfourpaperphrase{-a4paper}@onelevel@sanitizeAfourpaperphrase
        %
        newcommandgobbletoletterpaperphrase{}%
        expandafterlongexpandafterdef
        expandaftergobbletoletterpaperphraseexpandafter#expandafter1letterpaperphrase{}%
        %
        newcommandgobbletoAfourpaperphrase{}%
        expandafterlongexpandafterdef
        expandaftergobbletoAfourpaperphraseexpandafter#expandafter1Afourpaperphrase{}%
        %
        newcommandkeepBeforeAfourpaperphrase{}%
        expandafterlongexpandafterdef
        expandafterkeepBeforeAfourpaperphrase
        expandafter#expandafter1Afourpaperphrase#2relax{#1}%
        %
        newcommandCheckWhetherJobNameHasLetterpaperphrase{}%
        expandafterdef
        expandafterCheckWhetherJobNameHasLetterpaperphrase
        expandafter{%
        romannumeral0expandafterCheckWhetherNullexpandafter{%
        romannumeral0@firstofone{expandafterexpandafterexpandafter} %
        expandaftergobbletoletterpaperphrase
        romannumeral0@firstofone{expandafterexpandafterexpandafter} %
        expandafterjobname
        letterpaperphrase
        }%
        { @secondoftwo}%
        { @firstoftwo}%
        }%
        newcommandCheckWhetherJobNameHasAfourpaperphrase{}%
        expandafterdef
        expandafterCheckWhetherJobNameHasAfourpaperphrase
        expandafter{%
        romannumeral0expandafterCheckWhetherNullexpandafter{%
        romannumeral0@firstofone{expandafterexpandafterexpandafter} %
        expandaftergobbletoAfourpaperphrase
        romannumeral0@firstofone{expandafterexpandafterexpandafter} %
        expandafterjobname
        Afourpaperphrase
        }%
        { @secondoftwo}%
        { @firstoftwo}%
        }%
        CheckWhetherJobNameHasLetterpaperphrase{%
        PassOptionsToClass{letterpaper}{moderncv}%
        }{%
        PassOptionsToClass{a4paper}{moderncv}%
        }%
        IfFileExists{jobname.tex}{%
        newcommandmyinfile{jobname.tex}%
        }{%
        newcommandmyinfile{%
        CheckWhetherJobNameHasAfourpaperphrase
        {expandafterkeepBeforeAfourpaperphrasejobnamerelax}%
        {jobname}.tex%
        }%
        }%
        newcommandcreateletterdocument{%
        ShellEscape{%
        latexmk -cd
        -gg
        -jobname="CheckWhetherJobNameHasAfourpaperphrase
        {expandafterkeepBeforeAfourpaperphrasejobnamerelax}%
        {jobname}%
        letterpaperphrase"
        -pdflatex="lualatex @percentchar O @percentchar S"
        -pdf -dvi- -ps-
        myinfile
        }%
        }%
        AtBeginDocument{%
        begingroup
        immediatewrite@mainaux{stringglobalstringletstringcreateletterdocument=stringempty}%
        endgroup
        CheckWhetherJobNameHasLetterpaperphrase{}{createletterdocument}%
        }%
        makeatother

        % some preamble stuff before `documentclass` line
        % blah blah (preamble)
        % more blah blah (preamble)

        documentclass[11pt,sans]{moderncv} % <----- paper size is _not_
        % set here but is set via PassOptionsToClass.

        makeatletter
        @ifundefined{pdfpagewidth}{}{pdfpagewidth=paperwidth}%
        @ifundefined{pdfpageheight}{}{pdfpageheight=paperheight}%
        @ifundefined{pagewidth}{}{pagewidth=paperwidth}%
        @ifundefined{pageheight}{}{pageheight=paperheight}%
        makeatother

        % a lot more preamble lines after `documentclass` line
        moderncvstyle{classic}
        usepackage{graphicx}

        firstname{John}
        familyname{Doe}

        address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
        phone[mobile]{123 456 7890}
        email{someone@xyz.com}
        photo[64pt][0.5pt]{example-image-a}


        begin{document}
        makecvtitle
        end{document}






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 20 at 11:11

























        answered Feb 18 at 21:38









        Ulrich DiezUlrich Diez

        4,930618




        4,930618






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475503%2fhow-to-automatically-create-multiple-versions-of-a-document-with-different-paper%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?