-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Custom styles for ODT (and maybe LaTeX and RST) writers #2106
Comments
It is possible to alter the styles in the docx after the generation is complete. For example, here I set the style for all tables to BlueTableStyle (which is a style in the template dotx I use to generate docx from pandoc). The styles are contained in the document.xml file inside the docx archive. Obviously this is not an ideal solution and being able for pandoc to spit out the desired style name given the right directives would be great, similar to how you can specify them for HTML. I don't see why they would need different input syntax, the use-case for generating different styles based on output type is a can of worms best left closed.
|
I am in the exact same situation : writing a book and the publisher insists on docx file format using their custom styles. Is there any chance this could get implemented ? The workaround proposed works really great when you want to style all given elements the same way, or rename a given style to some other one. But when just some elements needs to use a specific style I don't see how it can be made to work. Thanks ! |
@krtek4, I ended up using docutils's rst2odt tool with the --odf-config-file and --stylesheet options to customize the output styles, which ended up suiting by needs just enough (with a few minor customizations to better handle images, code, etc.). I haven't found time to clean up my build process well enough to publish it, but if you're interested I can do a quick sweep, tar it up and send it to you. If so, drop me an email to not further pollute this issue. |
I'm writing a book for Packt, which also uses a crappy docx template. I'm now using pandoc to convert my markdown file to docx, and afer that use a couple of XSLT steps to convert the styles from pandoc to the styles required by the template from Packt. This seems to work ok for the styles I'm currently using (basic bullets, lists, images etc.) I haven't needed tables yet, but that should also be doable I guess. If you're interested let me know. |
Hi @josdirksen, Finally I am use Hadn't thought of XSLT at the time, but that is also definitively a great idea :) Good continuation with your book. |
Is this request fulfilled with http://pandoc.org/MANUAL.html#custom-styles-in-docx-output ? (at least for docx) |
As far as I can tell, this is exactly what is needed for docx. It is really similar to the feature I am using in |
Since this feature was implemented in docx, we might think about doing the same for ODT, ICML and maybe LaTeX and RST writers... |
From a quick glance at the docs, I think what I requested in this issue would be made possible with that new feature. However, I've long since finished writing my book, so I have no specific interest in this feature anymore, so feel free to close this issue (or leave it open if someone else wants to do actual testing of the feature and report back). |
@mb21: I am very much interested in this for odt, and available to test. |
@simongareste Personally, I'm not too familiar with the ODT format... feel free to take a look at the writer generating the OpenDocument format and the one packaging it into a .odt zip, pull requests welcome! |
Unfortunately I'm not a Haskell developer, but here are some specs to help a little:
<text:p text:style-name="Text_20_body">
this is a <text:span text:style-name="mystyle">custom style span</text:span>
</text:p>`
<style:style style:name="mystyle" style:family="text">
<style:text-properties fo:font-weight="bold"/>
</style:style> I propose that the custom style is bold by default, so that it will be visible in the output. Of course, by using a custom template, the user can define his own style. |
I'm reposting here some discussion from the now closed #2542
Since the following already works for docx output:
the idea is to change the syntax (and probably AST representation) to use a class with the
and make it work for ODT and ICML (and maybe even LaTeX and RST) as well (although for RST output, pandoc already uses the
|
Writing ::: {.projection}
Executing reverse bias polarity on neurowafer 1 of 7.
Estimated time remaining: 3h 39m 57s
::: Thanks to #168, this produces the expected output: <div class="projection">
<pre><code>Executing reverse bias polarity on neurowafer 1 of 7.
Estimated time remaining: 3h 39m 57s</code></pre>
</div> However, when the output is ConTeXt, this produces the astonishing result: \starttyping
Executing reverse bias polarity on neurowafer 1 of 7.
Estimated time remaining: 3h 39m 57s
\stoptyping I consider it astonishing because the \starttyping[class=projection]
Executing reverse bias polarity on neurowafer 1 of 7.
Estimated time remaining: 3h 39m 57s
\stoptyping Since pandoc cannot presume environments exist, it would be convenient if there was a command line argument that indicates that they do. Consider:
Here, the \startprojection
\starttyping
Executing reverse bias polarity on neurowafer 1 of 7.
Estimated time remaining: 3h 39m 57s
\stoptyping
\stopprojection Returning to the HTML output, if the source document contains: ::: {.style-projection}
Executing reverse bias polarity on neurowafer 1 of 7.
Estimated time remaining: 3h 39m 57s
::: This would produce: <div class="style-projection">
<pre><code>Executing reverse bias polarity on neurowafer 1 of 7.
Estimated time remaining: 3h 39m 57s</code></pre>
</div> Clearly, the |
Hello there, I do agree that it would be convenient to have a way to tell pandoc "create an environment, I know what I am doing" but instead of a general option, I guess that an extension would be more adapted. Something in the line of:
That would allow for the extension to be output dependent, which is probably needed. Fenced divs are great, let's make good use of those :) Thanks |
An extension would also work, though my preference would be for slightly different names: pandoc -f markdown -t context+environments
pandoc -f markdown -t latex+environments |
Ah, I just meant to advocate for extension vs. option. I don't really care about the name, provided it's meaningful. |
In order to use the fenced div class syntax for custom-styles, the user has to specify his intent to use the div as such an environment - either by switching on an extension (e.g. The prefix is more verbose, but also more explicit: you then could have multiple divs in the same document and have only some converted to custom-styles aka environments. The writers could then strip the |
On the duplicate #4139, I had asked for just a simple translation from A third option is that this could depend on the writer, implicit for ODT/DOCX/HTML, explicit for LaTex and friends that change the actual output structure. I suspect this is also not preferred by @jgm, but Pandoc already has implicit HTML support and I think a div.class is semantically identical to a paragraph.style which is why the implicit rule could be extended to this type of document structured output... |
Yes. It's redundant, verbose, inconsistent, and assumes pandoc-specific implementation knowledge. (Aside, there's no way to know how many times a style will be used in a given document.)
Seems to violate the KISS principle: it incurs extra work (post-processing) to strip the prefix. Simpler (for writers) to not use or require a prefix altogether. |
@DaveJarvis but you agree that the toggle-by-extension-approach has the disadvantage that in one document, you cannot use some divs for custom-styling while using other divs for other purposes, right? |
There can be options for both scenarios. For example, the custom styles could be explicitly listed once on the command line (or read from an external data source), rather than repeated throughout the text, freeing the unlisted div demarcations for other purposes. Or, depending on what list is shorter, an option to list the unstyled divs may be useful. Also, a
|
So we have three options now (the exact naming/implementation is also still debatable):
I'd like to get some feedback from more people on which of the three they prefer... @jgm? |
I think I prefer (a) explicit over implict, and (b) not having to change the command-line every time you change the source file (or consult a long file as reference for the sake of constructing a command line). For those reasons, FWIW, I guess I like the first option (
So -- BUT I'm not sure I see why |
I've been trying to build a filter for We essentially have to substitute the default Is this feasible with custom filters? |
From the LaTeX output perspective, one problem with converting the class to an environment is: inevitably someone will want to pass arguments (positional, optional, and potentially keyword) to the environment. I don't see how to specify those arguments in a way that would not interfere with other writers. We already have a few examples of filters for LaTeX to convert the class to to an environment, and I've been playing with a filter that uses data attributes to pass the environment and arguments. To me, this seems more like a problem for filters and explicit markup than the core readers. |
Hello, thanks for this awesome tool !! Is there a way to set a custom style information in a Latex input file and have it into the output odt, similar to what's done here with markdown input ? Or also something (filter and so on) that's able to catch dummy Latex commands at reader side like this
to be converted in a markdown block
to be able to reuse the odt custom styles repository already created (reaching the same result with two step conversion latex->markdown->odt). I've tried the Latex Thanks! |
Maybe a bit out of track, custom styles for ODT has been implemented by this commit. And this can be used from Pandoc 2.10. So, LaTeX and RST writers don't have custom styles now? I would like to share this update information who are searching custom styles for ODT. |
Did you find a way to accomplish this? We are currently encountering almost the same issue, but our output is docx. |
This sounds like a bug. Why don't you submit a new issue about this, with a minimal sample and complete instructions for reproducing? |
I misunderstood a colegue of mine, ignore that part. Though we are still intrested in getting custom styles in latex -> docx conversion working. |
Unfortunately, I don't quite understand the Haskell code. Do I understand it correctly that spans or paragraphs with the attribute "custom-style" should be rendered in the target ODT document with the character or paragraph style given with this attribute? Should the ODT writer create this style in the target document? Despite everything I tried, this does not seem to happen for me. I have tried several things, the "custom-style" attribute appears with its value in the "native" format of pandoc but I can't find it in the For example I have this in my Markdown file: Some Text, [StyledTestText]{custom-style="MyStyle"}, and boring stuff after. The "native" output of pandoc gives me:
But when running pandoc --reference-doc=reference.odt -f markdown -t odt -o testdoc.odt testdoc.md in <text:p text:style-name="Text_20_body">Some Text, StyledTestText, and boring stuff after.</text:p> Do I need to enable rendering of custom-styles somehow or is this a bug or am I understanding everything wrong? By the way:
|
Indeed @jgm states that commit should allow it to work: bde3d76#commitcomment-39238082 — but with my ignorance of Haskell it sure does look like it is specific to Abstract metadata... The docs suggest only DOCX and ICML support EDIT: however the changelog for 2.10 shows |
@niun — I just tested from the command line:
And out.odt does have the |
The other issue I think is that this only works for block paragraphs, not inline styles? |
@iandol -- thanks for testing this. Now I did some additional tests and yes, inline styles are not supported and for the paragraph style, I used the example from the pandoc manual. Which looks like this:
I was not aware that the vertical bars at the start of the line are creating a line block which seems also not to be supported for custom styles with the ODT writer. So if the style is in the reference document (does not matter if built-in or custom) and the text is a normal paragraph (annotated with "fences"), than the custom styling is working. @jgm custom inline styles for ODT writer would be a real treat. Or is there some working way of annotating inline styles, I am not aware of? |
I don't know of another markup syntax that works, and yes it would be great to extend the already supported block syntax to the inline case. |
I'm going to close this issue, which is too diffuse. |
Currently, you can customize formatting by providing some customized styles in a reference odt/docx file to pandoc. These styles are copied into the generated document and applied to selected elements in the document.
However, this only supports a limited, hard-coded list of styles. E.g. the 'Heading 1' style is applied to level-1 headings, the 'Text body' style to regular paragraphs, the 'Bullet Symbols' style to bullets. On top of this, I'd like to be able to specify other styles to use, on a block-by-block basis.
My usecase is that I'm writing a book, and my publisher requires the text to be delivered in docx or odt format, using a set of custom styles with non-standard style names. I have two challenges:
If I have some way to specify custom style names in the AST, I can use a pandoc filter to introduce the proper style names in the AST and have the writers use the right styles. Ideally, I'd be able to specify the style names for challenge 2 above directly in my markdown source.
Attributes seem like a good fit for this, so that would work out to something like this in markdown:
Note that this is already supported by the current markdown parser, and results in this JSON:
However, converting this to ODT or DOCX drops the attributes completely.
I'm aware that not all elements currently allow specifying styles, but that's another discussion. What I'd like to see is that, for all elements that currently support attributes, the "style" attribute be interpreted as a style name in the ODT and DOCX writes.
ODT and DOCX have a distinction between paragraph and character styles, but it seems that using the paragraph styles for block elements and character styles for inline elements is sufficient?
Does this sound reasonable? Is the "style" attribute the right fit here? For the HTML writer, the style attribute should contain a bit of raw CSS. I don't think we can have a single syntax that works for both HTML and ODT/DOCX, though perhaps we can have something that allows specifying two distinct attributes to allow working with both? At first glance, the class is more appropriate than an attribute, since a class is also a name that indirectly specifies formatting to be used. However, a class can be specified multiple times, which I don't think is applicable to DOCX / ODT styles? Or perhaps just use the first / last class name specified?
I'll likely spend a bit of time implementing this for my own needs, but I'd rather know up-front if this has any chance of being merged.
@mpickering, It seems that such a style= attribute could perhaps also be used by an asciidoc reader to fix #1234 / #1235.
The text was updated successfully, but these errors were encountered: