Compiling latex directly from R












9















I want to find a programmatic way of converting a .tex latex document to pdf.



What I usually do, and this works in most cases, is to use:



tools::texi2dvi(latexfile, pdf = TRUE, clean = TRUE)


However, I now need to work with documents that contain Asian fonts (Chinese, Japanese and Korean). Searching on tex.stackexchange.com leads to advice to incude the following lines in the tex file:



usepackage{xeCJK}
setCJKmainfont{MS Mincho} % for rmfamily


This means I need to use xelatex to build the pdf. I have tried variations on the following theme, none of which work.



shell(cmd="xelatex latexfile", mustWork=TRUE, translate=TRUE)


Question: How can I call xelatex programmatically?



Additional information:




  • I am on Windows 7, R2.13-1


  • xelatex is installed on my machine and works fine if I call it any other way (including via the command line)

  • I am using StatET in Eclipse










share|improve this question















migrated from stackoverflow.com Sep 27 '11 at 11:30


This question came from our site for professional and enthusiast programmers.














  • 1





    but what happens when you run that shell() expression? what is the error?

    – mdsumner
    Sep 27 '11 at 8:46











  • If you are using MiKTeX, its texi2dvi executable has a --engine=ENGINE option. So you could call it directly through shell

    – James
    Sep 27 '11 at 11:24











  • I notice that this question was migrated from StackOverflow to tex.stackexchange. This makes no sense at all - my question is not a latex question, but an R programming question.

    – Andrie
    Sep 27 '11 at 12:30











  • I agree, but you should have asked it accurately in the first place . . . it's about control over spawning commands to the system from R (possibly via a 3rd party) on windows :)

    – mdsumner
    Sep 27 '11 at 12:37











  • @mdsumner Yes, it could have been more accurate. And I would have made it more accurate if I understood more about the problem. Thanks very much for your help!

    – Andrie
    Sep 27 '11 at 12:46
















9















I want to find a programmatic way of converting a .tex latex document to pdf.



What I usually do, and this works in most cases, is to use:



tools::texi2dvi(latexfile, pdf = TRUE, clean = TRUE)


However, I now need to work with documents that contain Asian fonts (Chinese, Japanese and Korean). Searching on tex.stackexchange.com leads to advice to incude the following lines in the tex file:



usepackage{xeCJK}
setCJKmainfont{MS Mincho} % for rmfamily


This means I need to use xelatex to build the pdf. I have tried variations on the following theme, none of which work.



shell(cmd="xelatex latexfile", mustWork=TRUE, translate=TRUE)


Question: How can I call xelatex programmatically?



Additional information:




  • I am on Windows 7, R2.13-1


  • xelatex is installed on my machine and works fine if I call it any other way (including via the command line)

  • I am using StatET in Eclipse










share|improve this question















migrated from stackoverflow.com Sep 27 '11 at 11:30


This question came from our site for professional and enthusiast programmers.














  • 1





    but what happens when you run that shell() expression? what is the error?

    – mdsumner
    Sep 27 '11 at 8:46











  • If you are using MiKTeX, its texi2dvi executable has a --engine=ENGINE option. So you could call it directly through shell

    – James
    Sep 27 '11 at 11:24











  • I notice that this question was migrated from StackOverflow to tex.stackexchange. This makes no sense at all - my question is not a latex question, but an R programming question.

    – Andrie
    Sep 27 '11 at 12:30











  • I agree, but you should have asked it accurately in the first place . . . it's about control over spawning commands to the system from R (possibly via a 3rd party) on windows :)

    – mdsumner
    Sep 27 '11 at 12:37











  • @mdsumner Yes, it could have been more accurate. And I would have made it more accurate if I understood more about the problem. Thanks very much for your help!

    – Andrie
    Sep 27 '11 at 12:46














9












9








9


3






I want to find a programmatic way of converting a .tex latex document to pdf.



What I usually do, and this works in most cases, is to use:



tools::texi2dvi(latexfile, pdf = TRUE, clean = TRUE)


However, I now need to work with documents that contain Asian fonts (Chinese, Japanese and Korean). Searching on tex.stackexchange.com leads to advice to incude the following lines in the tex file:



usepackage{xeCJK}
setCJKmainfont{MS Mincho} % for rmfamily


This means I need to use xelatex to build the pdf. I have tried variations on the following theme, none of which work.



shell(cmd="xelatex latexfile", mustWork=TRUE, translate=TRUE)


Question: How can I call xelatex programmatically?



Additional information:




  • I am on Windows 7, R2.13-1


  • xelatex is installed on my machine and works fine if I call it any other way (including via the command line)

  • I am using StatET in Eclipse










share|improve this question
















I want to find a programmatic way of converting a .tex latex document to pdf.



What I usually do, and this works in most cases, is to use:



tools::texi2dvi(latexfile, pdf = TRUE, clean = TRUE)


However, I now need to work with documents that contain Asian fonts (Chinese, Japanese and Korean). Searching on tex.stackexchange.com leads to advice to incude the following lines in the tex file:



usepackage{xeCJK}
setCJKmainfont{MS Mincho} % for rmfamily


This means I need to use xelatex to build the pdf. I have tried variations on the following theme, none of which work.



shell(cmd="xelatex latexfile", mustWork=TRUE, translate=TRUE)


Question: How can I call xelatex programmatically?



Additional information:




  • I am on Windows 7, R2.13-1


  • xelatex is installed on my machine and works fine if I call it any other way (including via the command line)

  • I am using StatET in Eclipse







xetex compiling r scripts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:35









Community

1




1










asked Sep 27 '11 at 8:21









AndrieAndrie

176110




176110




migrated from stackoverflow.com Sep 27 '11 at 11:30


This question came from our site for professional and enthusiast programmers.









migrated from stackoverflow.com Sep 27 '11 at 11:30


This question came from our site for professional and enthusiast programmers.










  • 1





    but what happens when you run that shell() expression? what is the error?

    – mdsumner
    Sep 27 '11 at 8:46











  • If you are using MiKTeX, its texi2dvi executable has a --engine=ENGINE option. So you could call it directly through shell

    – James
    Sep 27 '11 at 11:24











  • I notice that this question was migrated from StackOverflow to tex.stackexchange. This makes no sense at all - my question is not a latex question, but an R programming question.

    – Andrie
    Sep 27 '11 at 12:30











  • I agree, but you should have asked it accurately in the first place . . . it's about control over spawning commands to the system from R (possibly via a 3rd party) on windows :)

    – mdsumner
    Sep 27 '11 at 12:37











  • @mdsumner Yes, it could have been more accurate. And I would have made it more accurate if I understood more about the problem. Thanks very much for your help!

    – Andrie
    Sep 27 '11 at 12:46














  • 1





    but what happens when you run that shell() expression? what is the error?

    – mdsumner
    Sep 27 '11 at 8:46











  • If you are using MiKTeX, its texi2dvi executable has a --engine=ENGINE option. So you could call it directly through shell

    – James
    Sep 27 '11 at 11:24











  • I notice that this question was migrated from StackOverflow to tex.stackexchange. This makes no sense at all - my question is not a latex question, but an R programming question.

    – Andrie
    Sep 27 '11 at 12:30











  • I agree, but you should have asked it accurately in the first place . . . it's about control over spawning commands to the system from R (possibly via a 3rd party) on windows :)

    – mdsumner
    Sep 27 '11 at 12:37











  • @mdsumner Yes, it could have been more accurate. And I would have made it more accurate if I understood more about the problem. Thanks very much for your help!

    – Andrie
    Sep 27 '11 at 12:46








1




1





but what happens when you run that shell() expression? what is the error?

– mdsumner
Sep 27 '11 at 8:46





but what happens when you run that shell() expression? what is the error?

– mdsumner
Sep 27 '11 at 8:46













If you are using MiKTeX, its texi2dvi executable has a --engine=ENGINE option. So you could call it directly through shell

– James
Sep 27 '11 at 11:24





If you are using MiKTeX, its texi2dvi executable has a --engine=ENGINE option. So you could call it directly through shell

– James
Sep 27 '11 at 11:24













I notice that this question was migrated from StackOverflow to tex.stackexchange. This makes no sense at all - my question is not a latex question, but an R programming question.

– Andrie
Sep 27 '11 at 12:30





I notice that this question was migrated from StackOverflow to tex.stackexchange. This makes no sense at all - my question is not a latex question, but an R programming question.

– Andrie
Sep 27 '11 at 12:30













I agree, but you should have asked it accurately in the first place . . . it's about control over spawning commands to the system from R (possibly via a 3rd party) on windows :)

– mdsumner
Sep 27 '11 at 12:37





I agree, but you should have asked it accurately in the first place . . . it's about control over spawning commands to the system from R (possibly via a 3rd party) on windows :)

– mdsumner
Sep 27 '11 at 12:37













@mdsumner Yes, it could have been more accurate. And I would have made it more accurate if I understood more about the problem. Thanks very much for your help!

– Andrie
Sep 27 '11 at 12:46





@mdsumner Yes, it could have been more accurate. And I would have made it more accurate if I understood more about the problem. Thanks very much for your help!

– Andrie
Sep 27 '11 at 12:46










3 Answers
3






active

oldest

votes


















3














With some help from the helpful people at StackOverflow, two things emerged:




  1. The correct way to call xelatex using a shell script from R is to remove the path from the full filename.



  2. The reason that xelatex doesn't return control is because it enters interactive mode when detecting an error. To fix this, use the argument --mode=batchmode:



    shell(cmd=paste("xelatex --mode=batchmode", basename(latexfile)), 
    mustWork=TRUE, intern=TRUE, translate=TRUE)







share|improve this answer

































    2














    You could also try texi2dvi with an environment variableLATEX=xelatex (not tested).



    See the source code of tools::texi2dvi (lines 145-147):



    ...
    latex <- if (pdf)
    Sys.getenv("PDFLATEX", "pdflatex")
    else Sys.getenv("LATEX", "latex")
    ...





    share|improve this answer































      0














      I eventually ended up with the following solution:



      install.packages("tinytex")   
      require("tinytex")}
      install_tinytex(force = TRUE)
      tlmgr_install('montserrat')
      xelatex('Report.tex')


      This code install TinyTex, then it installs the font package montserrat with tlmgr_install function.






      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%2f29649%2fcompiling-latex-directly-from-r%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









        3














        With some help from the helpful people at StackOverflow, two things emerged:




        1. The correct way to call xelatex using a shell script from R is to remove the path from the full filename.



        2. The reason that xelatex doesn't return control is because it enters interactive mode when detecting an error. To fix this, use the argument --mode=batchmode:



          shell(cmd=paste("xelatex --mode=batchmode", basename(latexfile)), 
          mustWork=TRUE, intern=TRUE, translate=TRUE)







        share|improve this answer






























          3














          With some help from the helpful people at StackOverflow, two things emerged:




          1. The correct way to call xelatex using a shell script from R is to remove the path from the full filename.



          2. The reason that xelatex doesn't return control is because it enters interactive mode when detecting an error. To fix this, use the argument --mode=batchmode:



            shell(cmd=paste("xelatex --mode=batchmode", basename(latexfile)), 
            mustWork=TRUE, intern=TRUE, translate=TRUE)







          share|improve this answer




























            3












            3








            3







            With some help from the helpful people at StackOverflow, two things emerged:




            1. The correct way to call xelatex using a shell script from R is to remove the path from the full filename.



            2. The reason that xelatex doesn't return control is because it enters interactive mode when detecting an error. To fix this, use the argument --mode=batchmode:



              shell(cmd=paste("xelatex --mode=batchmode", basename(latexfile)), 
              mustWork=TRUE, intern=TRUE, translate=TRUE)







            share|improve this answer















            With some help from the helpful people at StackOverflow, two things emerged:




            1. The correct way to call xelatex using a shell script from R is to remove the path from the full filename.



            2. The reason that xelatex doesn't return control is because it enters interactive mode when detecting an error. To fix this, use the argument --mode=batchmode:



              shell(cmd=paste("xelatex --mode=batchmode", basename(latexfile)), 
              mustWork=TRUE, intern=TRUE, translate=TRUE)








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Oct 6 '11 at 10:55

























            answered Sep 27 '11 at 12:45









            AndrieAndrie

            176110




            176110























                2














                You could also try texi2dvi with an environment variableLATEX=xelatex (not tested).



                See the source code of tools::texi2dvi (lines 145-147):



                ...
                latex <- if (pdf)
                Sys.getenv("PDFLATEX", "pdflatex")
                else Sys.getenv("LATEX", "latex")
                ...





                share|improve this answer




























                  2














                  You could also try texi2dvi with an environment variableLATEX=xelatex (not tested).



                  See the source code of tools::texi2dvi (lines 145-147):



                  ...
                  latex <- if (pdf)
                  Sys.getenv("PDFLATEX", "pdflatex")
                  else Sys.getenv("LATEX", "latex")
                  ...





                  share|improve this answer


























                    2












                    2








                    2







                    You could also try texi2dvi with an environment variableLATEX=xelatex (not tested).



                    See the source code of tools::texi2dvi (lines 145-147):



                    ...
                    latex <- if (pdf)
                    Sys.getenv("PDFLATEX", "pdflatex")
                    else Sys.getenv("LATEX", "latex")
                    ...





                    share|improve this answer













                    You could also try texi2dvi with an environment variableLATEX=xelatex (not tested).



                    See the source code of tools::texi2dvi (lines 145-147):



                    ...
                    latex <- if (pdf)
                    Sys.getenv("PDFLATEX", "pdflatex")
                    else Sys.getenv("LATEX", "latex")
                    ...






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 27 '11 at 12:50









                    rcsrcs

                    3,43321315




                    3,43321315























                        0














                        I eventually ended up with the following solution:



                        install.packages("tinytex")   
                        require("tinytex")}
                        install_tinytex(force = TRUE)
                        tlmgr_install('montserrat')
                        xelatex('Report.tex')


                        This code install TinyTex, then it installs the font package montserrat with tlmgr_install function.






                        share|improve this answer






























                          0














                          I eventually ended up with the following solution:



                          install.packages("tinytex")   
                          require("tinytex")}
                          install_tinytex(force = TRUE)
                          tlmgr_install('montserrat')
                          xelatex('Report.tex')


                          This code install TinyTex, then it installs the font package montserrat with tlmgr_install function.






                          share|improve this answer




























                            0












                            0








                            0







                            I eventually ended up with the following solution:



                            install.packages("tinytex")   
                            require("tinytex")}
                            install_tinytex(force = TRUE)
                            tlmgr_install('montserrat')
                            xelatex('Report.tex')


                            This code install TinyTex, then it installs the font package montserrat with tlmgr_install function.






                            share|improve this answer















                            I eventually ended up with the following solution:



                            install.packages("tinytex")   
                            require("tinytex")}
                            install_tinytex(force = TRUE)
                            tlmgr_install('montserrat')
                            xelatex('Report.tex')


                            This code install TinyTex, then it installs the font package montserrat with tlmgr_install function.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Feb 19 at 14:26

























                            answered Feb 19 at 14:14









                            Stepan S. SushkoStepan S. Sushko

                            1012




                            1012






























                                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%2f29649%2fcompiling-latex-directly-from-r%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

                                Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                                ComboBox Display Member on multiple fields

                                Is it possible to collect Nectar points via Trainline?