jalvesaq / Nvim-R

Vim plugin to work with R
GNU General Public License v2.0
968 stars 125 forks source link

Problem typesetting with xelatex #749

Closed marcocamilo closed 9 months ago

marcocamilo commented 1 year ago

I'm currently trying to typeset an Rmd file that knits multiple Rmd files into my thesis, but I'm having problems typesetting it in xelatex. The yaml heading includes the following lines, which work perfectly in RStudio:

output:
  bookdown::pdf_document2:
    template: "template.tex"
    fig_caption: TRUE
    latex_engine: xelatex
    keep_tex: TRUE

But when typesetting, I'm noticing the arguments sent by nvim-r to the console are:

/usr/local/bin/pandoc +RTS -K512m -RTS index.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output index.tex --lua-filter /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --include-in-header /var/folders/vd/1tcnpx3n25j4m4gs2vfxctdm0000gn/T//RtmphvEPXk/rmarkdown-str122bbbf639cf.html --citeproc 

The pdf-engine continues being --pdf-engine pdflatex.

The package has been working wonderfully so far, but with xelatex I'm having this issue. Here are the only lines for the package in my plugins.lua:

  -- R
  use ({ 'jalvesaq/Nvim-R',
    config = function()
      vim.g.R_auto_start = 1
      vim.g.R_openpdf = 1
    end
  })

Also, when I use \ka, it doesn't output the file where I want, as specified in my yaml header as:

knit: (function(inputFile, encoding) {
      out_dir <- 'output';
      output_file <- file.path(dirname(inputFile), out_dir, 'thesis.pdf');
      rmarkdown::render(inputFile,
                        encoding=encoding,
                        output_file=output_file,
                        runtime = "static") })

I don't know how to solve the issue :(

jalvesaq commented 1 year ago

I'm now using Quarto instead of Rmd, but I still have this ~/.latexmkrc (last modified in August 2018):

#/usr/bin/env perl

$pdf_mode = 2;
$pdflatex = 'xelatex -synctex=1 %O %S';
$pdf_previewer = "start zathura --unique";

$biber='biber --validate-datamodel %O %S';

If you believe Nvim-R's documentation could be improved regarding this issue, could you please make a pull request?

marcocamilo commented 1 year ago

Hi! Thanks for the response. Where would I have to save this code in my config? Since I'm using nvim (with lua), I'm not sure where would I need to include this snip of code.

jalvesaq commented 1 year ago

It's not a nvim config. It's a latexmk config: ~/.latexmkrc where ~ means your home directory.

marcocamilo commented 1 year ago

I created the file in my home directory, but still didn't work. I'm still seeing nvim-r sends the following command despite the yaml, when using \kp:

/usr/local/bin/pandoc +RTS -K512m -RTS index.knit.md --to latex 
--from markdown+autolink_bare_uris+tex_math_single_backslash 
--output index.tex --lua-filter /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua 
--lua-filter /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua
--self-contained --highlight-style tango 
--pdf-engine pdflatex --variable graphics --include-in-header /var/folders/vd/1tcnpx3n25j4m4gs2vfxctdm0000gn/T//RtmpnbHUiF/rmarkdown-str15f351fee7961.html --citeproc 

Particularly, the --pdf-engine pdflatex is still being used.

jalvesaq commented 1 year ago

It works here (Debian testing). The code that is output in the R console includes --pdf-engine xelatex.

Trying to guess the cause of the problem:

Anyway, I can't fix a bug that I can't replicate. So, a pull request is welcome.

marcocamilo commented 1 year ago

Hi,

I tried with output: pdf_document and it's working (at least the xelatex part). I'd have to change the cross-referencing, which is different in bookdown:pdf_document2, but what I'm still noticing is that the output document isn't saved in the target folder.

As I mentioned, I have in the YAML:

knit: (function(inputFile, encoding) {
      out_dir <- 'output';
      output_file <- file.path(dirname(inputFile), out_dir, 'thesis.pdf');
      rmarkdown::render(inputFile,
                        encoding=encoding,
                        output_file=output_file,
                        runtime = "static") })

How could this part be fixed?

Regarding the pull request, I could do it... but I've never done one for a plugin issue, so I'd be completely new (by the way, thank you for your patient responses :) ) If this could help make the bookdown:pdf_document2 work in the plugin, then I can try to send one :)

jalvesaq commented 1 year ago

I'm sorry, but I can't try to make bookdown::pdf_document2 work because I no longer use Rmd. I now write Quarto documents, and the main reason is that Quarto takes care of cross-references. If you want to fix the issue, you may start looking at the functions RMakeRmd (R/start_r.vim) and nvim.interlace.rmd (R/nvimcom/R/nvim.interlace.R). You also would have to rule out the possibility of the bug being in the bookdown package. Maybe it will be easier to try Quarto.

jalvesaq commented 9 months ago

Nvim-R is being superseded by R.nvim, a new project that will be inaugurated in a week at the R-nvim organization. Please, check out tmp-Nvim-R and help us to find the last remaining bugs before R.nvim inauguration. When the project is officially started, you will be able to open issues there and request new features.

Nvim-R will remain alive as a feature-frozen project for Vim users. If you want to know the reason, please, see this discussion.

You can reopen this issue if you could do a pull request to fix it. Thanks!