Replies: 4 comments
-
I don't think you can achieve this with Lua filters. Your best bet is probably postprocessing the docx produced by pandoc, and changing the styles, but I can't help with the details of that. |
Beta Was this translation helpful? Give feedback.
-
I don't have a lot of time to help you, but I can offer some basic information. For the sake of clarity, I'm going to call your "custom docx template" by the standard pandoc term "reference document." Assuming you can't change the style names in the reference document, you have two tools that you can use to produce those style names. One is custom styles and the other is a docx template. To use the former, your script will have to take a heading, for example, and replace it with a Para wrapped in a Div with a This approach won't work with things like the document title, because pandoc represents it as metadata rather than part of the document. But pandoc 3.2.1 added support for docx templates, so you can run However, if this is something you only have to do once, it may be faster to solve your problem manually instead of writing a script: use pandoc to produce a docx file with the reference document, and then use the styles pane in Word to apply the required styles manually. Presumably, most people writing papers for the conference will have to apply styles manually. |
Beta Was this translation helpful? Give feedback.
-
EDIT: Added note about reference document. Potentially some of it is solvable, but you need to know what type the data gets in the Pandoc AST to match it in a Lua filter, since the filter matches on object types. To understand this better, I usually use the native output to understand what the data comes in as, to correctly match it in a filter:
I then inspect the result (the file suffix is just made up) to find what the data I'm looking for becomes. In your case, I would then do the same with the template in Word. The title is metadata, so when you say it's styled as "Title_document", I suspect it's a heading you're referring to. The "Head1|" style might potentially be a paragraph style which becomes a pandoc.Para. I see that a lot with custom header styles. Now, having done this research, say we arrive at the conclusions that A conversion filter (
A template (
You will need to ensure you have a reference document that has the styles you want to use. Then it's a matter of giving Pandoc all the input: This is typed from memory from various attempts to do similar things, so you'll need to test it out and fix all the errors and incorrect assumptions. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the insights. I'll have to look closely into what route to take. As I'm not very familiar with Lua or Pandoc, manual post-processing will probably be the best this time. |
Beta Was this translation helpful? Give feedback.
-
I am new to Lua scripts and a rather novice to Pandoc. I'm trying to convert a Latex file to docx using a custom docx template. The docx template was not created by me but was provided by the scientific conference organization. They are using custom styles for almost every text element. I would like to create a Lua script that instructs Pandoc to use these custom styles. For example, the title of the paper (Latex: "\title{Title_of_paper}", is styled as "Title_document" in the template, not as the docx default "Title". There are many more custom styles used, like a heading at level 1 is styled as "Head1|", not a default "Heading 1". Being unfamiliar with Lua scripting, I asked an RAG based on ChatGPT, llama3 and Gemini for advice. None of which were successful, even for this apparently simple task.
Does anyone know whether this is even possible? What would the Lua script look like?
Again, formatting the title is just the beginning, even the images have their own style, so I will have to expand to almost every text element in the original Latex document.
Than you
Beta Was this translation helpful? Give feedback.
All reactions