Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latex pattern for raw table treatment is checked twice in Lua : perf improvement ? #11915

Open
cderv opened this issue Jan 21, 2025 · 0 comments
Labels
crossref enhancement New feature or request lua Issues related to the lua codebase, filter chain, etc maintenance performance tables Issues with Tables including the gt integration

Comments

@cderv
Copy link
Collaborator

cderv commented Jan 21, 2025

I just noticed this while reading code.

For raw LaTeX Table, we do process table patterns, only when found

elseif hasRawLatexTable(raw) then
for i,pattern in ipairs(_quarto.patterns.latexTablePatterns) do
local match_fun = _quarto.modules.patterns.match_all_in_table(pattern)
if match_fun(raw.text) then
local combined_pattern = _quarto.modules.patterns.combine_patterns(pattern)
raw.text = applyLatexTableCaption(raw.text, tblCaptions[idx], tblLabels[idx], combined_pattern)
break
end
end
idx = idx + 1
elseif hasPagedHtmlTable(raw) then

though we also do the exact same inside the function call

function applyLatexTableCaption(latex, tblCaption, tblLabel, tablePattern)
local latexCaptionPattern = _quarto.patterns.latexCaptionPattern
local latex_caption_match = _quarto.modules.patterns.match_all_in_table(latexCaptionPattern)
-- insert caption if there is none
local beginCaption, caption = latex_caption_match(latex)
if not beginCaption then
latex = latex:gsub(tablePattern, "%1" .. "\n\\caption{ }\\tabularnewline\n" .. "%2%3", 1)
end
-- apply table caption and label
local beginCaption, captionText, endCaption = latex_caption_match(latex)
if #tblCaption > 0 then
captionText = stringEscape(tblCaption, "latex")
end
if #tblLabel > 0 then
captionText = captionText .. " {#" .. tblLabel .. "}"
end
assert(captionText)
latex = latex:gsub(_quarto.modules.patterns.combine_patterns(latexCaptionPattern), "%1" .. captionText:gsub("%%", "%%%%") .. "%3", 1)
return latex
end

As those string matching were already a problem related to perf (#9733), maybe this is worth simplifying here to avoid the duplicate treatment

@cderv cderv added enhancement New feature or request lua Issues related to the lua codebase, filter chain, etc maintenance performance crossref tables Issues with Tables including the gt integration labels Jan 21, 2025
@cderv cderv changed the title latex pattern is checked twice in Lua : perf improvment ? latex pattern for raw table treatment is checked twice in Lua : perf improvement ? Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crossref enhancement New feature or request lua Issues related to the lua codebase, filter chain, etc maintenance performance tables Issues with Tables including the gt integration
Projects
None yet
Development

No branches or pull requests

1 participant