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

List of tables, list of equations, list of figures, and list of listings in html, odt, docx... #1965

Open
mbacou opened this issue Feb 20, 2015 · 17 comments

Comments

@mbacou
Copy link

mbacou commented Feb 20, 2015

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!

@mpickering
Copy link
Collaborator

I think this would be desirable but without looking at the current implementation I think the work would be quite involved.

@mbacou
Copy link
Author

mbacou commented Feb 20, 2015

Hi Matt,
Right, each writer would probably implement the tables of content quite differently, but might be worth starting with the most common ones like HTML and ODT? Markdown is so powerful when it comes to working with long shared documents, but having to compile these listings by hand is cumbersome (outside of LaTeX that is). HTML might be the easiest of all as there is no concept of page number there, just links to figures/tables in the document.

@mb21
Copy link
Collaborator

mb21 commented Feb 2, 2019

Closing in favour of #813

@mb21 mb21 closed this as completed Feb 2, 2019
@jgm jgm reopened this Feb 2, 2019
@jgm
Copy link
Owner

jgm commented Feb 2, 2019

I think this should be left open; it is independent of 813.

@mb21
Copy link
Collaborator

mb21 commented Feb 2, 2019

@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.

@ghost
Copy link

ghost commented Apr 15, 2019

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:

\starttext
  \input cover

  \startfrontmatter
    \completecontent[alternative=c]
  \stopfrontmatter

  \startbodymatter
    \input body
  \stopbodymatter
\stoptext

The \completecontent[alternative=c] inserts the table of contents, \completelistoffigures would insert a list of figures, etc. OpenOffice also has a mechanism for separate indexes based on tagged document content.

Primarily, this would benefit HTML, which lacks a simple listings mechanism derived from the document structure.

@countofsanfrancisco
Copy link

I would like this enhancement too.
Has this issue made any forward progress?

For a markdown text conversion to HTML, I think if the markdown does something like this:

<p id="table-some-name">My Table Caption 1</p>
<p id="table-another-name">My Other Table Caption 2</p>
<p id="figure-a-certain-img">A Figure Caption</p>
<p id="figure-another-img">Another Figure Image</p>

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.

@isaactpetersen
Copy link

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.

Repository owner deleted a comment from ickc Aug 22, 2022
@acxz
Copy link
Contributor

acxz commented Jul 24, 2024

Related issue for docx: #8245

@bpj
Copy link

bpj commented Jul 24, 2024

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 #list-of-tables and generate and insert the lists in those divs.

@acxz
Copy link
Contributor

acxz commented Jul 24, 2024

Here is a pandoc-crossref related issue: lierdakil/pandoc-crossref#299 regarding docx lot, lof.

@bpj
Copy link

bpj commented Jul 25, 2024

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?

@iandol
Copy link
Contributor

iandol commented Jul 25, 2024

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...

@awelormro
Copy link

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 }
}

@acxz
Copy link
Contributor

acxz commented Sep 22, 2024

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.
If someone is so inclined lofheading and lotheading could be options that can be added via a PR.
(this should probably be its own issue however, as this issue is an aggregation issue for lof and lot support in various formats)

@awelormro
Copy link

Does it always appear at very beginning or it can be called with something similar to \listoffigures \listoftables or similar commands?

@acxz
Copy link
Contributor

acxz commented Sep 23, 2024

It appears based on your template. The default template for msword/openxml is located here:

$if(toc)$
$toc$
$endif$
$if(lof)$
$lof$
$endif$
$if(lot)$
$lot$
$endif$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants