44kTblCap = " tbl-cap"
55kTblSubCap = " tbl-subcap"
66
7- local latexTableWithOptionsPattern = " (\\ begin{table}%[%w+%])(.*)(\\ end{table})"
8- local latexTablePattern = " (\\ begin{table})(.*)(\\ end{table})"
9- local latexLongtablePatternwWithPosAndAlign = " (\\ begin{longtable}%[[^%]]+%]{.*})(.*)(\\ end{longtable})"
10- local latexLongtablePatternWithPos = " (\\ begin{longtable}%[[^%]]+%])(.*)(\\ end{longtable})"
11- local latexLongtablePatternWithAlign = " (\\ begin{longtable}{.*})(.*)(\\ end{longtable})"
12- local latexLongtablePattern = " (\\ begin{longtable})(.*)(\\ end{longtable})"
13- local latexTabularPatternWithPosAndAlign = " (\\ begin{tabular}%[[^%]]+%]{.*})(.*)(\\ end{tabular})"
14- local latexTabularPatternWithPos = " (\\ begin{tabular}%[[^%]]+%])(.*)(\\ end{tabular})"
15- local latexTabularPatternWithAlign = " (\\ begin{tabular}{.*})(.*)(\\ end{tabular})"
16- local latexTabularPattern = " (\\ begin{tabular})(.*)(\\ end{tabular})"
17-
18- local latexTablePatterns = pandoc .List ({
19- latexTableWithOptionsPattern ,
20- latexTablePattern ,
21- latexLongtablePatternwWithPosAndAlign ,
22- latexLongtablePatternWithPos ,
23- latexLongtablePatternWithAlign ,
24- latexLongtablePattern ,
25- latexTabularPatternWithPosAndAlign ,
26- latexTabularPatternWithPos ,
27- latexTabularPatternWithAlign ,
28- latexTabularPattern ,
29- })
30-
317local latexCaptionPattern = " (\\ caption{)(.-)(}[^\n ]*\n )"
328
339function tableCaptions ()
@@ -52,8 +28,8 @@ function tableCaptions()
5228 el = pandoc .walk_block (el , {
5329 RawBlock = function (raw )
5430 if _quarto .format .isRawLatex (raw ) then
55- if raw .text :match (latexTabularPattern ) and not raw .text :match (latexTablePattern ) then
56- raw .text = raw .text :gsub (latexTabularPattern ,
31+ if raw .text :match (_quarto . patterns . latexTabularPattern ) and not raw .text :match (_quarto . patterns . latexTablePattern ) then
32+ raw .text = raw .text :gsub (_quarto . patterns . latexTabularPattern ,
5733 " \\ begin{table}\n\\ centering\n %1%2%3\n\\ end{table}\n " ,
5834 1 )
5935 return raw
@@ -198,7 +174,7 @@ function applyTableCaptions(el, tblCaptions, tblLabels)
198174 end
199175 raw .text = raw .text :gsub (captionPattern , " %1" .. captionText :gsub (" %%" , " %%%%" ) .. " %3" , 1 )
200176 elseif hasRawLatexTable (raw ) then
201- for i ,pattern in ipairs (latexTablePatterns ) do
177+ for i ,pattern in ipairs (_quarto . patterns . latexTablePatterns ) do
202178 if raw .text :match (pattern ) then
203179 raw .text = applyLatexTableCaption (raw .text , tblCaptions [idx ], tblLabels [idx ], pattern )
204180 break
@@ -250,40 +226,3 @@ function extractTblCapAttrib(el, name, subcap)
250226 end
251227 return nil
252228end
253-
254- function countTables (div )
255- local tables = 0
256- pandoc .walk_block (div , {
257- Table = function (table )
258- tables = tables + 1
259- end ,
260- RawBlock = function (raw )
261- if hasRawHtmlTable (raw ) or hasRawLatexTable (raw ) then
262- tables = tables + 1
263- end
264- end
265- })
266- return tables
267- end
268-
269-
270- function hasRawHtmlTable (raw )
271- if _quarto .format .isRawHtml (raw ) and _quarto .format .isHtmlOutput () then
272- return raw .text :match (htmlTablePattern ())
273- else
274- return false
275- end
276- end
277-
278- function hasRawLatexTable (raw )
279- if _quarto .format .isRawLatex (raw ) and _quarto .format .isLatexOutput () then
280- for i ,pattern in ipairs (latexTablePatterns ) do
281- if raw .text :match (pattern ) then
282- return true
283- end
284- end
285- return false
286- else
287- return false
288- end
289- end
0 commit comments