Skip to content

Enable searching home, project root, and file's directory for latexmkrc file#582

Merged
jalvesaq merged 2 commits into
R-nvim:mainfrom
todmorrison:patch-1
May 22, 2026
Merged

Enable searching home, project root, and file's directory for latexmkrc file#582
jalvesaq merged 2 commits into
R-nvim:mainfrom
todmorrison:patch-1

Conversation

@todmorrison
Copy link
Copy Markdown
Contributor

@todmorrison todmorrison commented May 21, 2026

This change enables searching home directory, cwd (typically the project root), and then file's directory for a ".latexmkrc" file. It does this in reverse of the stated order, so that the "most local" 'out_dir' configuration stands.

…ory for latexmkrc file

This change enables searching home directory, project root, and then file's directory for a ".latexmkrc" file. It does this in reverse of the stated order, so that the "most local" out_dir configuration stands.
Comment thread lua/r/rnw.lua Outdated
Comment on lines 597 to 609
for _, chkdir in pairs(chkdirs) do
if vim.fn.glob(chkdir .. "/.latexmkrc") ~= "" then
local ltxmk = vim.fn.readfile(vim.fn.expand(chkdir .. "/.latexmkrc"))
for _, line in ipairs(ltxmk) do
if
line:match('out_dir%s*=%s*"(.*)"')
or line:match("out_dir%s*=%s*'(.*)'")
then
vim.b.rplugin_pdfdir = line:match('out_dir%s*=%s*"(.*)"')
or line:match("out_dir%s*=%s*'(.*)'")
end
end
end
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for _, chkdir in pairs(chkdirs) do
if vim.fn.glob(chkdir .. "/.latexmkrc") ~= "" then
local ltxmk = vim.fn.readfile(vim.fn.expand(chkdir .. "/.latexmkrc"))
for _, line in ipairs(ltxmk) do
if
line:match('out_dir%s*=%s*"(.*)"')
or line:match("out_dir%s*=%s*'(.*)'")
then
vim.b.rplugin_pdfdir = line:match('out_dir%s*=%s*"(.*)"')
or line:match("out_dir%s*=%s*'(.*)'")
end
end
end
for _, chkdir in ipairs(chkdirs) do
local rcfile = vim.fn.expand(chkdir .. "/.latexmkrc")
if vim.fn.glob(rcfile) ~= "" then
for _, line in ipairs(vim.fn.readfile(rcfile)) do
vim.b.rplugin_pdfdir = line:match('out_dir%s*=%s*"(.*)"')
or line:match("out_dir%s*=%s*'(.*)'")
or vim.b.rplugin_pdfdir
end
end
end

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution.

Two small things:

  1. I would use ipairs
  2. Collapsed the inner if into a single assignment (the or gvim.b.rplugin_pdfdirg at the end preserves the current value when no match is found)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, ipairs does exactly what I intended (Thank you!) and the collapsed if is much better. I had simply left the existing logic thinking to minimize changes, but your version is so much cleaner.

Changes done. Thanks for the feedback/suggestions.

@PMassicotte
Copy link
Copy Markdown
Collaborator

Note: the CI style errors are expected.

Refactor loop to use ipairs for better behavior. Simplify the assignment of vim.b.rplugin_pdfdir.
@PMassicotte
Copy link
Copy Markdown
Collaborator

All good on my side :)

@jalvesaq
Copy link
Copy Markdown
Member

All good on my side :)

Thank you, @PMassicotte and @todmorrison! I'm no longer using LaTeX or Rnoweb to try the pull request carefully. Merging it now...

@jalvesaq jalvesaq merged commit 0c15985 into R-nvim:main May 22, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants