-
-
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
(enhancement) double proposal for the TOC #1612
Comments
👍 I like your proposals. |
I've been wanting this too: a way to specify in the doc that it should have a TOC rather than just at the command line. I have a use where I like to convert the documents automatically, so it can't tell the author's intent and choose to set such options on certain files without making some convention that gets pre-processed to allow the script to set options. I'm wondering if it might be simpler to make use of the fact that when the TOC is generated, it gets the ID of "TOC" and the fact that you can specify the ID of a header. You could simply tag the header you want to be the TOC section with the ID "TOC" and the TOC contents could be inserted there:
Given the default header ID names, you could just use "TOC" as the header, although in that case, you may want the TOC section title to be empty. If you decided that the generated TOC would replace any Markdown content in this section, this could actually allow you to manually make a TOC in the source file for plain text readability (which you would have to maintain) that would get replaced with the hyperlinked one:
You could maintain the plain text TOC by running the source through pandoc and emitting it in Markdown, which with this feature, would put the header list back into the designated TOC section, replacing the old list of headers. A drawback here might be that you would need to specify any extension enables and disables that you are using when running the conversion The hard part of coding this would be that it is a big change from how it works now which is the template handles it by adding it at the beginning if it is enabled. To put it anywhere would move that to being emitted in the body. A compromise could be to leave it at the top and just allow the TOC title to be set via YAML, enabling the --toc option as described. -Ryan On Sep 6, 2014, at 2:19 PM, Pablo Rodríguez notifications@github.com wrote:
|
Many thanks for your reply, @ryangray. I would rather use the lowercase
Your method is simpler, but if the user wants to have the title specified in the YAML metadata, it has to be typed again. If the title changes (what is often the case when you’re writting a book), it has to be replaced twice. I think this should be avoided. A compromise solution would be to repeat the title from YAML metadata with the following:
BTW, other identifiers and classes should be allowed with the table of contents, such as in:
[I must confess I’m not sure I get it.] Do you really think that it makes sense to write a table of content that doesn’t get in the final document? I guess that adding a comment could do the job here. |
On Oct 18, 2014, at 11:58 AM, Pablo Rodríguez notifications@github.com wrote:
since Pandoc will give it the ID of "#toc". I used #TOC since that's the ID pandoc assigns to the section it generates. Anyway, I think that the compromise sounds good. There could be a YAML variable, perhaps, "toc-title" that sets the title (if present) in the case where you just name the section "toc" or "TOC": toc-title: Contents tocSection 1[...] eqivalent to: Contents {#toc}Section 1[...]
I worded that a wrong when I said "which you would have to maintain". You wouldn't have to manually edit that section; you would manually run pandoc to make a new markdown version where it replaced that section with the new markdown toc text. It's probably not worth it since you'd have to run pandoc to convert your markdown file to a markdown file and give several options depending on your preferences in order to not change the style:
Currently, Pandoc will insert the generated toc content into a section with the ID of #toc now, but for markdown format output, it doesn't get put into a section like with HTML. For example, the source: Section 1Some stuff. Section 2More stuff. If you could designate the toc section and that section's content was replaced with the generated toc content, you could output to markdown format and Pandoc would put the toc in that section with the #toc ID, and that markdown source could be run back through Pandoc again to get the toc content updated without duplicating the toc in the resulting output. For the example source, toc
Section 1Some stuff. Section 2More stuff. Then, if we edit this file and add a section 3: Section 3Yet more stuff. then outputs with toc
Section 1Some stuff. Section 2More stuff. Section 3Yet more stuff. rather than duplicating the toc as it would now. We could use this as our new source file if we wanted. The benefit here would be having a readable toc at the top that we wouldn't have to manually update or remove when we edit the file. In other words, at this point, passing the result again through Also, the toc section could also be removed if the --toc option is not used. As you mention, you could also have the toc section title set from a YAML variable like, say, "toc-title" as well. This part was just a little idea that your original post made me think of and now seems like it's not really that useful for the work involved. -Ryan |
@ryangray, many thanks for your reply. Sorry for not having answered before, but it seems that I erased your reply before having read it.
At least in HTML, identifiers seem to be case-sensitive.
Why not simply Sorry, I still don’t get what you are trying to describe with the toc within the Markdown document. Allow me to quote a single sentence:
It took me a while to understand that the quoted part was written by me. It isn’t only the typo. In your reply, there is no way to distinguish my replies from the words I reply to (your ones). The only way to distinguish has been to read my previous message again. And even with your own message, I don’t know why you marked it as a comment. Sorry, I have to guess what could describe the benefit of your proposal:
If I get it right, the best way to do it would be to generate an ePub file and browse it with calibre. At least, this is what I do. calibre allows ePub document reloading, which eases the thing a bit. Is this what you meant? |
Proposal №2 raises an interesting question: what should we do with other meta-fields, like title, subtitle, authors, date and abstract? I feel like there should be a general templating extension for all of this, really. Pandoc's Markdown does support LaTeX commands, but using ,e.g. |
#458 is on the way. 😄 What about making the whole order of components configurable? There is a line in the sources: let meta' = title ++ subtitle ++ authors ++ date ++ toc ++ abstract Making just this line configurable via YAML would solve the entire "order problem". Later on, it can be extended by list of figures (lof) and list of tables (lot) or even later by bib|ref to allow ordering of all main components of a documents. |
@tolot27 this line is from docx writer code. Other writers have other ideas about what goes where -- and we have to consider all of them here. Which is, relatively speaking, hard. |
I guess, getting this ordering for LaTeX and other writers too, requires substantial changes, even for the templates. |
@lierdakil, many thanks for your comment. I think that other YAML fields can be configured with templates, but the table of contents, other lists (of figures and similar items) and the bibliography cannot be placed with templates. At least, as far as I know. I wasn’t thinking about LaTeX (this can be changed easily with the right template). I want to be able to place the TOC (and footnotes [as mentioned in #1720]) within an ePub file. I think this feature is useful for all formats. |
While it's all true on the topic of templates, why then not propose template variables for toc/bibliography? (I don't think pandoc supports lists of figures/tables/etc, although there are filters implementing this) Probably because you want table of contents/bibliography somewhere inside document body, and not directly at beginning/end? I think this could be useful for other meta-fields as well. EDIT: Apparently, there is template variable for table of contents in some output formats. Not sure about details though. |
+++ Nikolay Yakimov [Mar 30 15 00:51 ]:
There already is a template variable for toc. |
@lierdakil, there are two reasons for not doing that. The first one is that adding
The second reason is that it won’t work in most of the cases. It lacks flexibility. Without the YAML field A similar case are the final notes. Having all footnotes in a single chapter (for ePub files) is the only way to have unique note numbers. Otherwise, each chapter will start notes with number one (so you have x notes numbered 1). And in reading devices you don’t have a proper foot to place notes. Again, having a I think that from the user’s perspective, avoiding templates and implementing a built-in solution is much better. And way more flexible.
According to #1965, they might be implemented in the future.
@jgm, even ignoring the lack of flexibility of this approach, there is no |
+++ Pablo Rodríguez [Mar 30 15 10:23 ]:
You could add template variables for these things, ahead of the TOC, and populate the variables on the command line with something like
Why would you need this? An EPUB already has a master TOC. |
@jgm, do you really think that this is easier to use than my proposal? Sorry, but I don’t understand the command line option myself. I’m not sure whether this is an ad hoc hack for LaTeX. How about other formats? (I was actually thinking of ePub and ConTeXt.) Another drawback is that your suggested option doesn’t allow to have a single source document. Sorry, but the approach suggested above can be implemented in pandoc itself.
I removed the TOC, but I was interested in showing the reader what contents were to be found in the book before the reading activity begun. |
+++ Pablo Rodríguez [Mar 30 15 11:16 ]:
For context you could use
EPUB is more difficult, because internally we have several different
Then why remove the TOC? |
Sorry, but how is this approach simpler and more flexible? Instead of implementing a simple You are hardcoding TOC title and to change TOC placement a special option is needed. What is wrong in the following proposal?
Again, wouldn’t it be easier the proposal from the sample above?
It was simply misplaced, before both the epigraph and the dedication. In that case, no TOC was better than a misplaced TOC. |
+++ Pablo Rodríguez [Mar 30 15 12:18 ]:
I didn't say it was. I was responding to your claim that it "wasn't possible" to add an epigraph using existing pandoc. But, there are a couple of ways in which the template approach is more flexible. First, as I mentioned, in a template you can include styling appropriate to each output format. Maybe in an EPUB the epigraph goes in a special div, while in context it goes in an epigraph environment. I don't see how your proposal addresses that, unless the idea is just that the contents of the section under the header "epigraph" populates the "epigraph" variable in a template, in which case I really don't see the advantage. Second, templates are flexible because (unlike pandoc source code) the user can modify them at will. You wanted "epigraph," and you can have it. Someone else will want "forward" or "epilogue." The range of such requests is literally endless -- everyone wants something a bit different. The template system is designed to accommodate people's different needs.
In most formats TOC title isn't hard coded. Some formats simply don't include a title (though you can easily add one to the the template); others (like LaTeX) will generate the title automatically depending on language settings. I think it might make sense to have a standard
I think the template approach is more flexible. E.g. what if you want the epigraph to appear above the title, with a line under it? What if you want it to appear in one kind of environment in LaTeX output, and another in HTML? It's easy to make this happen using templates, but your approach would make it impossible. Also, I imagine that people writing in languages other than English might object to section headers like "epigraphs." Again, with templates you can name the variables whatever you like. |
@jgm, many thanks for your reply. Sorry, but right now I’m in a hurry. I hope I will find the time to answer in a day or two. |
@jgm, sorry for not having expressed myself accurately. What I’m trying to propose here aims to be a usability improvement for any pandoc user. I’m not trying to solve an issue with my documents. I think that templates are harder to use than extended Markdown files. I can use them myself (this is not the problem). Templates are more problematic for most newbies with no coding experience. Those users don’t contribute either to the discussion list or don’t open issues here. They are the reason why I consider that templates should be avoided whenever it is possible. My proposal is about titles and placement of sections with automatically–generated content. I agree that templates may modify TOC title placement, but I think that a more general approach would be better for the user. A TOC placed at the end of the document would require another template. And a TOC placed at the end of the document but before the colophon would require a different template. With the proposal I’m trying explain below, no templates would be needed. This would ease the task for the end–user. Sorry, but I don’t see a problem with different formats in different chapters and different output files. Classes or identifiers should be used here. A sample with dedication, epigraph and colophon (requires # Dedication {.hidden #dedication}
Dedicated to them.
This tiny contribution is a small sign of my deep gratitude for their
huge achievements.
# [Epigraph] {.hidden #epigraph}
“If I have seen further it is by standing on the shoulders of giants.”
(Isaac Newton, _Letter to R. Hooke_)
# [Colophon] {.hidden #colophon}
This book was generated with `pandoc` (<http://pandoc.org/>) and
typeset with <span class="tex-logo">ConTeXt</span>
(<http://contextgarden.net/>).
_<span class="tex-logo">TeX</span> Gyre Pagella_, _GFS Didot_ and
_Cousine_ were the selected typefaces. The required CSS code is (removing for #dedication {
padding-top: 15%;
margin-right: 5%;
margin-left: 50%;
}
#dedication p {
margin: 0%;
padding: 0%;
margin-top: 10%;
line-height: 120%;
text-align: right;
font-style: italic;
text-indent: 0%;
}
#epigraph {
padding-top: 25%;
margin-right: 5%;
margin-left: 50%;
}
#epigraph p {
margin: 0%;
padding: 0%;
margin-top: 10%;
line-height: 120%;
text-align: right;
text-indent: 0%;
}
.hidden>h1 {
visibility: hidden;
margin: 0%;
padding: 0%;
font-size: 0pt;
} ConTeXt can compile XML sources. This way, no information is lost in the translation. Required code would be (partly adapted from https://github.com/ousia/context-environments/blob/master/pandoc-xhtml.tex): \startxmlsetups xml:pandoc
\xmlsetsetup{\xmldocument}{[@id='dedication']}{xml:dedication}
\xmlsetsetup{\xmldocument}{[@id='epigraph']}{xml:epigraph}
\xmlsetsetup{\xmldocument}{[@id='colophon']}{xml:colophon}
\xmlregistersetup{xml:pandoc}
\xmlregistersetup{xml:pandoc}
\startxmlsetups xml:dedication
\startdedicationmakeup
\xmlflush{#1}
\stopdedicationmakeup
\stopxmlsetups
\startxmlsetups xml:epigraph
\startepigraphmakeup
\xmlflush{#1}
\stopepigraphmakeup
\stopxmlsetups
\startxmlsetups xml:colophon
\startcolophonmakeup
\xmlflush{#1}
\stopcolophonmakeup
\stopxmlsetups
\definemakeup[dedication][style=\em, top=\vskip.1\paperheight,
setups=setups:dedication, align={left, nothyphenated}, pagestate=start]
\setuplayout[dedication][backspace=.6\textwidth, cutspace=\cutspace,
width=middle]
\definemakeup[epigraph][top=\vskip.2\paperheight, align={flushright,
nothyphenated}, pagestate=start]
\setuplayout[epigraph][backspace=.33\paperwidth, cutspace=\cutspace,
width=middle] I have published a book with the above settings at work: ePub version, PDF dedication, PDF epigraph and PDF colophon. The PDF document is composed for print, so pages on the right are the ones that contain dedication, epigraph and colophon. BTW, I’m writing a document describing the way from pandoc to ConTeXt. I expect to release it soon.
I see that the What I meant with hard coded TOC title is that the user cannot set a common different title for all output formats.
There are three different issues here:
Sorry, I don’t get it: # Contenidos {#toc}
# [Cita] {.hidden #epigrafe}
# [Dedicatoria] {.hidden #dedicatoria} The only reserved identifier name above is You could also reserve identifier names in different languages, but I think this shouldn’t be required. |
2015-04-04 11:57 GMT+03:00 Pablo Rodríguez notifications@github.com:
|
+++ Pablo Rodríguez [Apr 04 15 01:57 ]:
This would require hard-coding a special treatment of these designated classes in every output format -- quite a lot of work. The idea behind templates and filters was to provide a generic way for users to customize to their needs and tastes.
That's still the case, though further changes to make all the writers (not just EPUB) pay attention to the
The point is that what it takes to add the line will differ wildly from one format to another. In HTML it requires some CSS, in LaTeX a special command, etc. IF this is all handled in templates, that's no problem, because the templates are already format-specific. But it is hard to see how any customizations like this could be handled if special treatments of these environments were hard-baked into the pandoc writers.
Well, then the pandoc writer modules would have to know that I certainly see how there's a use for a tool that allows people to do what you're suggesting, with output to several formats (say HTML, LaTeX/ConTeXt/PDF, EPUB). I would suggest creating a third-party tool on top of pandoc. This could be done by supplying a filter and perhaps some specialized templates, and some python or shell script to glue it together. (Or the whole thing could be done in Haskell, leading to a standalone executable.) The filter could go through the document and convert specially marked sections into the appropriate kinds of code for the output format (e.g. a dedication). Pandoc is already flexible enough to provide the basis for such a tool, that would do everything you've described. |
Sorry, but my point is not about formatting any section (not even the TOC itself, layout should be always left to the user), but about being able to place the TOC in a different position in any document. And the reason for being able to place the TOC is that pandoc locates it at a fixed position in the document.
Sorry, but not at all. The only reserved unique identifier there would be Writer modules would only need to know about And about the internationalization layer for reserved names (only for sections with content automatically generated by pandoc), I think it should be the same as YAML metadata fields. As far as I know, they are available only in English. And this is fine. The proposal here can be summarized with the following question. First, let me quote from #771:
If this is easier, why isn’t it when it is a I think this is exactly the same case. |
(Sorry, you were talking about epigraphs and the like, so I
It's technically feasible, I think, in both cases. The proposal would be to (1) remove toc variables from the templates (2) rewrite all writer modules to give special treatment to (3) remove the (4) remove the writerTableOfContents field from WriterOptions. (5) rewrite pandoc-citeproc so that instead of appending the (6) remove special yaml metadata fields that affect I'm cautiously in favor. But these are not small changes, |
Many thanks for your reply, @jgm. I’m fine with both options, but I wonder whether option 1 would break existing compatibility. I mean, would the user have to insert a header with a |
+++ Pablo Rodríguez [Apr 09 15 12:46 ]:
These weren't meant as options. All the numbered items were separate pieces of a single proposal, to be accomplished jointly. |
OK, then it’s fine for me. |
Can't we leave template as an option? There are some cases where #toc It shouldn't be that hard to keep both options: if there is "toc" heading 2015-04-09 23:26 GMT+03:00 Pablo Rodríguez notifications@github.com:
|
I wrote a long post, and then realized that this will be better-served to be discussed on pandoc-discuss, so I suggest to continue there: https://groups.google.com/forum/#!topic/pandoc-discuss/HxmpFK-Ydus |
After the discussion in pandoc-discuss, Is there any chance to get this by pandoc-1.14? |
Any updates about this? |
@jgm, now that version 2.0 has been released, could this be considered?
or simply:
If I’m not confused, this is the same way |
Just to be sure I understood correctly this proposal, will it allow pandoc to take into account the restructured-text My side this feature missing is the only reason I still have to use docutils for a large amount of documentation. |
@LuisBL - yes. Currently the TOC is interpolated into a template variable, so it can't be placed in an arbitrary location in the document body. The suggestion is to change that. |
Sorry if I miss the info, will this feature be implemented? If so, do you know when? Thanks. |
The proposal for both TOC title and placement can be simplified without the need of any YAML metadata field.
@ryangray proposed this before, but I didn’t get his proposal then (Ryan, my apologies for not having understood your proposal, which was simpler and better).
All it is required is reserving unique identifier names for sections with automatically–generated contents. In this case it would be
{#toc}
.Titles would be included in headings themselves:
This way they could also be placed where the user wants.
The same logic could be applied for references (reserving identifier
{#references}
) and footnotes (reserving name{#footnotes}
).I append the original proposal as a comment for historical purposes.
The text was updated successfully, but these errors were encountered: