@@ -448,81 +448,84 @@ end, function(float)
448448 local made_fix = false
449449 local function fix_raw (is_star_env )
450450 local function set_raw (el )
451- if _quarto .format .isRawLatex (el ) and _quarto .modules .patterns .match_all_in_table (_quarto .patterns .latexLongtablePattern )(el .text ) then
452- made_fix = true
453- local raw = el
454- -- special case for longtable floats in LaTeX
455- local extended_pattern = {" .-" }
456- for _ , pattern in ipairs (_quarto .patterns .latexLongtablePattern ) do
457- table.insert (extended_pattern , pattern )
458- end
459- table.insert (extended_pattern , " .*" )
460- local longtable_preamble , longtable_begin , longtable_content , longtable_end , longtable_postamble = _quarto .modules .patterns .match_all_in_table (extended_pattern )(raw .text )
461- if longtable_preamble == nil or longtable_begin == nil or longtable_content == nil or longtable_end == nil or longtable_postamble == nil then
462- warn (" Could not parse longtable parameters. This could happen because the longtable parameters\n " ..
463- " are not well-formed or because of a bug in quarto. Please consider filing a bug report at\n " ..
464- " https://github.com/quarto-dev/quarto-cli/issues/, and make sure to include the document that\n " ..
465- " triggered this error." )
466- return {}
467- end
468- -- split the content into params and actual content
469- -- params are everything in the first line of longtable_content
470- -- actual content is everything else
471- local start , content = split_longtable_start (longtable_begin .. longtable_content )
472- if start == nil or content == nil then
473- warn (" Could not parse longtable parameters. This could happen because the longtable parameters\n " ..
474- " are not well-formed or because of a bug in quarto. Please consider filing a bug report at\n " ..
475- " https://github.com/quarto-dev/quarto-cli/issues/, and make sure to include the document that\n " ..
476- " triggered this error." )
477- return {}
478- end
479- local cap_loc = cap_location (float )
480- if float .parent_id then
481- -- need to fixup subtables because longtables don't support subcaptions,
482- -- and longtable captions increment the wrong counter
483- -- we try our best here
484-
485- fatal (" longtables are not supported in subtables.\n " ..
486- " This is not a Quarto bug - the LaTeX longtable environment doesn't support subcaptions.\n " )
487- return {}
488- end
489- if is_star_env then
490- -- content: table payload
491- -- start: \\begin{longtable}... command
492- -- longtable_preamble: everything that came before the \\begin{longtable} command
493- -- longtable_postamble: everything that came after the \\end{longtable} command
494- local result = pandoc .Blocks ({
495- pandoc .RawBlock (" latex" , longtable_preamble ),
496- pandoc .RawBlock (" latex" , " \\ begin{table*}" ),
497- -- caption here if cap_loc == "top"
498- pandoc .RawBlock (" latex" , start .. " \n " .. content .. " \n\\ end{longtable}" ),
499- -- caption here if cap_loc ~= "top"
500- pandoc .RawBlock (" latex" , " \\ end{table*}" ),
501- pandoc .RawBlock (" latex" , longtable_postamble ),
502- })
503- if cap_loc == " top" then
504- result :insert (3 , latex_caption )
505- -- gets around the padding that longtable* adds
506- result :insert (4 , pandoc .RawBlock (" latex" , " \\ vspace{-1em}" ))
507- else
508- result :insert (4 , latex_caption )
451+ if _quarto .format .isRawLatex (el ) then
452+ local longtable_match , longtable_pattern = _quarto .modules .patterns .match_in_list_of_patterns (el .text , _quarto .patterns .latexLongtableEnvPatterns )
453+ if longtable_match and longtable_pattern then
454+ made_fix = true
455+ local raw = el
456+ -- special case for longtable floats in LaTeX
457+ local extended_pattern = {" .-" }
458+ for _ , pattern in ipairs (longtable_pattern ) do
459+ table.insert (extended_pattern , pattern )
509460 end
510- return result
511- else
512- local result = pandoc .Blocks ({latex_caption , pandoc .RawInline (" latex" , " \\ tabularnewline" )})
513- -- if cap_loc is top, insert content on bottom
514- if cap_loc == " top" then
515- result :insert (pandoc .RawBlock (" latex" , content ))
461+ table.insert (extended_pattern , " .*" )
462+ local longtable_preamble , longtable_begin , longtable_content , longtable_end , longtable_postamble = _quarto .modules .patterns .match_all_in_table (extended_pattern )(raw .text )
463+ if longtable_preamble == nil or longtable_begin == nil or longtable_content == nil or longtable_end == nil or longtable_postamble == nil then
464+ warn (" Could not parse longtable parameters. This could happen because the longtable parameters\n " ..
465+ " are not well-formed or because of a bug in quarto. Please consider filing a bug report at\n " ..
466+ " https://github.com/quarto-dev/quarto-cli/issues/, and make sure to include the document that\n " ..
467+ " triggered this error." )
468+ return {}
469+ end
470+ -- split the content into params and actual content
471+ -- params are everything in the first line of longtable_content
472+ -- actual content is everything else
473+ local start , content = split_longtable_start (longtable_begin .. longtable_content )
474+ if start == nil or content == nil then
475+ warn (" Could not parse longtable parameters. This could happen because the longtable parameters\n " ..
476+ " are not well-formed or because of a bug in quarto. Please consider filing a bug report at\n " ..
477+ " https://github.com/quarto-dev/quarto-cli/issues/, and make sure to include the document that\n " ..
478+ " triggered this error." )
479+ return {}
480+ end
481+ local cap_loc = cap_location (float )
482+ if float .parent_id then
483+ -- need to fixup subtables because longtables don't support subcaptions,
484+ -- and longtable captions increment the wrong counter
485+ -- we try our best here
486+
487+ fatal (" longtables are not supported in subtables.\n " ..
488+ " This is not a Quarto bug - the LaTeX longtable environment doesn't support subcaptions.\n " )
489+ return {}
490+ end
491+ if is_star_env then
492+ -- content: table payload
493+ -- start: \\begin{longtable}... command
494+ -- longtable_preamble: everything that came before the \\begin{longtable} command
495+ -- longtable_postamble: everything that came after the \\end{longtable} command
496+ local result = pandoc .Blocks ({
497+ pandoc .RawBlock (" latex" , longtable_preamble ),
498+ pandoc .RawBlock (" latex" , " \\ begin{table*}" ),
499+ -- caption here if cap_loc == "top"
500+ pandoc .RawBlock (" latex" , start .. " \n " .. content .. " \n\\ end{longtable}" ),
501+ -- caption here if cap_loc ~= "top"
502+ pandoc .RawBlock (" latex" , " \\ end{table*}" ),
503+ pandoc .RawBlock (" latex" , longtable_postamble ),
504+ })
505+ if cap_loc == " top" then
506+ result :insert (3 , latex_caption )
507+ -- gets around the padding that longtable* adds
508+ result :insert (4 , pandoc .RawBlock (" latex" , " \\ vspace{-1em}" ))
509+ else
510+ result :insert (4 , latex_caption )
511+ end
512+ return result
516513 else
517- result :insert (1 , pandoc .RawBlock (" latex" , content ))
514+ local result = pandoc .Blocks ({latex_caption , pandoc .RawInline (" latex" , " \\ tabularnewline" )})
515+ -- if cap_loc is top, insert content on bottom
516+ if cap_loc == " top" then
517+ result :insert (pandoc .RawBlock (" latex" , content ))
518+ else
519+ result :insert (1 , pandoc .RawBlock (" latex" , content ))
520+ end
521+ result :insert (1 , pandoc .RawBlock (" latex" , start ))
522+ result :insert (1 , pandoc .RawBlock (" latex" , longtable_preamble ))
523+ result :insert (pandoc .RawBlock (" latex" , " \\ end{longtable}" ))
524+ result :insert (pandoc .RawBlock (" latex" , longtable_postamble ))
525+ return result
518526 end
519- result :insert (1 , pandoc .RawBlock (" latex" , start ))
520- result :insert (1 , pandoc .RawBlock (" latex" , longtable_preamble ))
521- result :insert (pandoc .RawBlock (" latex" , " \\ end{longtable}" ))
522- result :insert (pandoc .RawBlock (" latex" , longtable_postamble ))
523- return result
524527 end
525- end
528+ end
526529 end
527530 return set_raw
528531 end
0 commit comments