-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
List of tables, list of equations, list of figures, and list of listings in html, odt, docx... #1965
Comments
I think this would be desirable but without looking at the current implementation I think the work would be quite involved. |
Hi Matt, |
Closing in favour of #813 |
I think this should be left open; it is independent of 813. |
@jgm Well... in my mind 813 has morphed into "Add attributes, auto_identifiers to tables and figures and generate listings of them". But yes, maybe it makes sense to keep it separate. |
TeX-based typesetting engines have a way of generating lists of tables, figures, equations, contents, etc. Typically it's fairly trivial, such as the following ConTeXt example:
The Primarily, this would benefit HTML, which lacks a simple listings mechanism derived from the document structure. |
I would like this enhancement too. For a markdown text conversion to HTML, I think if the markdown does something like this:
Pandoc can key off the text "table-" and "figure-" to differentiate between a figure and a table and auto generate a list of tables or list of figures from a markdown text and using the enclosing text as the caption for that table. For figures, you can use the MD syntax too. For me, I don't need the figures or tables to be numbered. |
I vote for this feature, as well. It would be nice to be able to output lists of tables and figures to html and other formats. |
Related issue for docx: #8245 |
The filter pandoc-crossref does LOT, LOF and list of codeblocks/listings and more for LaTeX and HTML-like formats. For LaTeX it mostly unloads to LaTeX but it provides syntax for captions, labels and crossrefs which Pandoc Markdown (mostly) lacks. List of tables and list of figures should be relatively straightforward to do with a Lua filter for formats where the list need only contain links and not page/chapter numbers or the like since those elements have captions already. It would be relatively straightforward to first walk the document top down and collect the captions, and possibly insert numbering into the caption, then do a second pass looking for divs with appropriate ids like |
Here is a pandoc-crossref related issue: lierdakil/pandoc-crossref#299 regarding docx lot, lof. |
Come to think of it would docx generate those lists automatically if you insert the right snippet of XML somewhere? Maybe that can be done with a template now? |
quarto-dev/quarto-cli#2464 (reply in thread) But @acxz just opened #10029 to add lof and lot to the docx writer, so perhaps no need to make use of the cool new templates for this... |
I have made something similar to this, with the snippets shown above and a lua filter, that works to make indexes for figures, tables and table of contents, you can define the metadata values toctitledocx, loftitledocx, lottitledocx in case you want something different from the standard ones, and also, if in some cases \listoftables or \listoffigures make something weird, I have made something as a backup using \listoftablesdocx and \listoffiguresdocx the filter is: function Meta(meta)
toctitle = meta.toctitledocx
loftitle = meta.loftitledocx
lottitle = meta.lottitledocx
toctitledocx = meta.toctitledocx
loftitledocx = meta.loftitledocx
lottitledocx = meta.lottitledocx
end
function Para(el)
local indextable = [[
<w:sdt>
<w:sdtPr><w:docPartObj><w:docPartGallery w:val="Table of Contents" /><w:docPartUnique /></w:docPartObj></w:sdtPr>
<w:sdtContent>
<w:p><w:pPr><w:pStyle w:val="TOCHeading" /></w:pPr><w:r><w:t xml:space="preserve">Table of Contents</w:t></w:r></w:p>
<w:p><w:r><w:fldChar w:fldCharType="begin" w:dirty="true" />
<w:instrText xml:space="preserve">TOC \o "1-3" \h \z \u</w:instrText>
<w:fldChar w:fldCharType="separate" /><w:fldChar w:fldCharType="end" /></w:r></w:p>
</w:sdtContent>
</w:sdt>
]]
local loftable = [[
<w:sdt>
<w:sdtPr><w:docPartObj><w:docPartGallery w:val="Table of Figures" /><w:docPartUnique /></w:docPartObj></w:sdtPr>
<w:sdtContent>
<w:p><w:pPr><w:pStyle w:val="TOCHeading" /></w:pPr><w:r><w:t xml:space="preserve">Table of Figures</w:t></w:r></w:p>
<w:p><w:r><w:fldChar w:fldCharType="begin" w:dirty="true" />
<w:instrText xml:space="preserve">TOC \h \z \t "Image Caption" \c</w:instrText>
<w:fldChar w:fldCharType="separate" /><w:fldChar w:fldCharType="end" /></w:r></w:p>
</w:sdtContent>
</w:sdt>
]]
local lottable = [[
<w:sdt>
<w:sdtPr><w:docPartObj><w:docPartGallery w:val="List of Tables" /><w:docPartUnique /></w:docPartObj></w:sdtPr>
<w:sdtContent>
<w:p><w:pPr><w:pStyle w:val="TOCHeading" /></w:pPr><w:r><w:t xml:space="preserve">List of Tables</w:t></w:r></w:p>
<w:p><w:r><w:fldChar w:fldCharType="begin" w:dirty="true" />
<w:instrText xml:space="preserve">TOC \h \z \t "Table Caption" \c</w:instrText>
<w:fldChar w:fldCharType="separate" /><w:fldChar w:fldCharType="end" /></w:r></w:p>
</w:sdtContent>
</w:sdt>
]]
if toctitle then
indextable = string.gsub(indextable, ">Table of Contents<", ">"..toctitle.."<")
-- print(indextable)
end
if loftitle then
loftable = string.gsub(loftable, ">Table of Figures<", ">"..loftitle.."<")
end
if lottitle then
lottable = string.gsub(lottable, ">List of Tables<", ">"..lottitle.."<")
end
if #el.content == 1 and el.content[1].text == "\\tableofcontents" then
return pandoc.RawBlock("openxml", indextable)
elseif #el.content == 1 and el.content[1].text == "\\listoffigures" then
-- Insertamos el bloque en formato OpenXML
return pandoc.RawBlock("openxml", loftable)
elseif #el.content == 1 and el.content[1].text == "\\listoftables" then
-- Insertamos el bloque en formato OpenXML
return pandoc.RawBlock("openxml", lottable)
end
end
function RawBlock(el)
local indextable = [[
<w:sdt>
<w:sdtPr><w:docPartObj><w:docPartGallery w:val="Table of Contents" /><w:docPartUnique /></w:docPartObj></w:sdtPr>
<w:sdtContent>
<w:p><w:pPr><w:pStyle w:val="TOCHeading" /></w:pPr><w:r><w:t xml:space="preserve">Table of Contents</w:t></w:r></w:p>
<w:p><w:r><w:fldChar w:fldCharType="begin" w:dirty="true" />
<w:instrText xml:space="preserve">TOC \o "1-3" \h \z \u</w:instrText>
<w:fldChar w:fldCharType="separate" /><w:fldChar w:fldCharType="end" /></w:r></w:p>
</w:sdtContent>
</w:sdt>
]]
if toctitle then
indextable = string.gsub(indextable, ">Table of Contents<", ">"..toctitledocx.."<")
-- print(indextable)
end
local loftable = [[
<w:sdt>
<w:sdtPr><w:docPartObj><w:docPartGallery w:val="Table of Figures" /><w:docPartUnique /></w:docPartObj></w:sdtPr>
<w:sdtContent>
<w:p><w:pPr><w:pStyle w:val="TOCHeading" /></w:pPr><w:r><w:t xml:space="preserve">Table of Figures</w:t></w:r></w:p>
<w:p><w:r><w:fldChar w:fldCharType="begin" w:dirty="true" />
<w:instrText xml:space="preserve">TOC \h \z \t "Image Caption" \c</w:instrText>
<w:fldChar w:fldCharType="separate" /><w:fldChar w:fldCharType="end" /></w:r></w:p>
</w:sdtContent>
</w:sdt>
]]
local lottable = [[
<w:sdt>
<w:sdtPr><w:docPartObj><w:docPartGallery w:val="List of Tables" /><w:docPartUnique /></w:docPartObj></w:sdtPr>
<w:sdtContent>
<w:p><w:pPr><w:pStyle w:val="TOCHeading" /></w:pPr><w:r><w:t xml:space="preserve">List of Tables</w:t></w:r></w:p>
<w:p><w:r><w:fldChar w:fldCharType="begin" w:dirty="true" />
<w:instrText xml:space="preserve">TOC \h \z \t "Table Caption" \c</w:instrText>
<w:fldChar w:fldCharType="separate" /><w:fldChar w:fldCharType="end" /></w:r></w:p>
</w:sdtContent>
</w:sdt>
]]
if loftitle then
loftable = string.gsub(loftable, ">Table of Figures<", ">"..loftitle.."<")
end
if lottitle then
lottable = string.gsub(lottable, ">List of Tables<", ">"..lottitle.."<")
end
if el.format == "tex" and el.text == "\\tableofcontents" then
-- print("Será rawblock para el tex")
return pandoc.RawBlock("openxml", indextable)
elseif el.format == "tex" and el.text == "\\listoffiguresdocx" then
-- Insertamos el bloque en formato OpenXML
return pandoc.RawBlock("openxml", loftable)
elseif el.format == "tex" and el.text == "\\listoftablesdocx" then
-- Insertamos el bloque en formato OpenXML
return pandoc.RawBlock("openxml", lottable)
end
end
function Div(el)
local loftable = [[
<w:sdt>
<w:sdtPr><w:docPartObj><w:docPartGallery w:val="Table of Figures" /><w:docPartUnique /></w:docPartObj></w:sdtPr>
<w:sdtContent>
<w:p><w:pPr><w:pStyle w:val="TOCHeading" /></w:pPr><w:r><w:t xml:space="preserve">Table of Figures</w:t></w:r></w:p>
<w:p><w:r><w:fldChar w:fldCharType="begin" w:dirty="true" />
<w:instrText xml:space="preserve">TOC \h \z \t "Image Caption" \c</w:instrText>
<w:fldChar w:fldCharType="separate" /><w:fldChar w:fldCharType="end" /></w:r></w:p>
</w:sdtContent>
</w:sdt>
]]
local lottable = [[
<w:sdt>
<w:sdtPr><w:docPartObj><w:docPartGallery w:val="List of Tables" /><w:docPartUnique /></w:docPartObj></w:sdtPr>
<w:sdtContent>
<w:p><w:pPr><w:pStyle w:val="TOCHeading" /></w:pPr><w:r><w:t xml:space="preserve">List of Tables</w:t></w:r></w:p>
<w:p><w:r><w:fldChar w:fldCharType="begin" w:dirty="true" />
<w:instrText xml:space="preserve">TOC \h \z \t "Table Caption" \c</w:instrText>
<w:fldChar w:fldCharType="separate" /><w:fldChar w:fldCharType="end" /></w:r></w:p>
</w:sdtContent>
</w:sdt>
]]
if loftitle then
loftable = string.gsub(loftable, ">Table of Figures<", ">"..loftitle.."<")
end
if lottitle then
lottable = string.gsub(lottable, ">List of Tables<", ">"..lottitle.."<")
end
if el.classes[2] == "list-of-fig" then
-- Insertamos el bloque en formato OpenXML
return pandoc.RawBlock("openxml", loftable)
elseif el.classes[2] == "list-of-tbl" then
-- Insertamos el bloque en formato OpenXML
return pandoc.RawBlock("openxml", lottable)
end
end
return {
{ Meta = Meta },
{ Para = Para },
{ Div = Div },
{ RawBlock = RawBlock }
}
|
Status update on this, with #8245 closed, docx has lof and lot support. You can remove docx from the initial asking of this issue. The next release of pandoc (3.5) will probably have the related commits. Note a generic listing is still not possible as far as I'm aware of with vanilla pandoc, see more complete crossref solutions like pandoc-crossref, Quarto, etc. for that. @awelormro's docx solution should be used if you need to rename your List of Figures or List of Tables headings. Otherwise, using the builtin pandoc lof and lot suffices without dealing with Lua filters. |
Does it always appear at very beginning or it can be called with something similar to \listoffigures \listoftables or similar commands? |
It appears based on your template. The default template for msword/openxml is located here: pandoc/data/templates/default.openxml Lines 50 to 58 in f3fff87
|
List of tables, list of equations, list of figures, and list of listings are needed in all writers, not just LaTeX. These are important elements in any technical or scientific paper and report, as important as citations and bibliographies. Could you clarify whether this feature might be implemented in all common formats (.html, .odt, .docx, etc.)? Thanks!
The text was updated successfully, but these errors were encountered: