Replies: 5 comments 19 replies
-
Did they say why? For docx, did you try using a I can't help with an index; presumably Word has a way to generate an index but I'm not familiar. |
Beta Was this translation helpful? Give feedback.
-
See #6415 for an existing issue on native Pandoc indices. There are some Pandoc filter solutions there. For DOCX you could easily parse some custom markup and inject in the raw XML to turn a list of words into indexable ones I think... EDIT: ODT has much simpler markup for this and IMO a nicer index system in its GUI, you may want to use ODT then convert to DOCX if neccesary... ODT index mark: This is a <text:alphabetical-index-mark-start text:id="IMark105553265462528"/>baby<text:alphabetical-index-mark-end text:id="IMark105553265462528"/> DOCX index mark: <w:t xml:space="preserve">This </w:t></w:r><w:r w:rsidR="00ED0D90" w:rsidRPr="00861EFF"><w:t xml:space="preserve">is a </w:t></w:r><w:r w:rsidRPr="00861EFF"><w:t>baby</w:t></w:r><w:r w:rsidRPr="00861EFF"><w:fldChar w:fldCharType="begin"/></w:r><w:r w:rsidRPr="00861EFF"><w:instrText xml:space="preserve"> XE "baby" </w:instrText></w:r><w:r w:rsidRPr="00861EFF"><w:fldChar w:fldCharType="end"/></w:r><w:r w:rsidR="006C0245" w:rsidRPr="00861EFF"><w:t> |
Beta Was this translation helpful? Give feedback.
-
This is a minimal piece of code that works. Now if I find a way to insert it into the docx using a Python script, it will be Christmas! :-) |
Beta Was this translation helpful? Give feedback.
-
Ok, I'm not proud of this code but it does the job. The filter that replaces \index{term} with !!!INDEX(term)!!!:
The docx modifier that replaces !!!INDEX(term)!!! with the index entry:
|
Beta Was this translation helpful? Give feedback.
-
Scrivener is awesome. You work using semantic styles (block and inline), and an outliner where each chunk of a document can get a semantic type. These styles and types are styled containers that can be wrapped in markup at compile time, where the native Scrivener project is converted to any output you desire. It does DOCX/ODT/EPUB/LaTeX etc. natively, but the power lies in combining it to pandoc. It spits out pandoc-flavoured markdown, which can then be processed automatically (Scrivener can run pandoc command for you). For example this is an index entry in the Scrivener editor: This will get converted to
Right, as @jgm mentions, this needs wrapping and careful addition.
There are a couple linked to #6415 as workarounds. However, they do some more complex things. I modified an older lua filter to convert --[[
convertIndex.lua: convert \index{item} markup for marking up words for an
index into ODT and Typst native alternatives.
For ODT it uses the native XML markup for index items.
For Typst, you also need https://typst.app/universe/package/in-dexter
Author: Ian Max Andolina
Version: 1.00
Copyright: (c) 2024 Ian Max Andolina License=MIT, see LICENSE for details
]]
local stringify = (require 'pandoc.utils').stringify
local counter = nil
local function formatindex(format, key) --returns a rawinline for tex, odt and typst
if not counter then counter = 1 end
if format:match 'latex' then
key = "\\index{" .. key .. "}"
return pandoc.RawInline('tex', key)
elseif format:match 'odt' or format:match 'opendocument' then
key = "<text:alphabetical-index-mark-start text:id=\"" .. stringify(counter) .. "\"/>" .. key .. "<text:alphabetical-index-mark-end text:id=\"" .. stringify(counter) .. "\"/>"
counter = counter + 1
return pandoc.RawInline('opendocument', key)
elseif format:match 'typst' then
key = key .. "#index[" .. key .. "]"
return pandoc.RawInline('typst', key)
else
return key
end
end
function RawInline(r) -- parse rawinlines looking for a tex \index{key} to convert
local fmt = FORMAT
if fmt:match("odt") then fmt = "opendocument" end
if fmt:match("tex") then fmt = "latex" end
kw = stringify(r.text)
if string.match(r.format, "tex") and string.match(kw, "\\index") then
kw = kw:match("\\index{(.-)}")
if string.len(kw) > 0 then
return formatindex(fmt, kw)
end
end
end You run it like this:
The ODT generated by pandoc has the correct markup to generate an index, no more tweaking necessary: |
Beta Was this translation helpful? Give feedback.
-
Hi! I'm working on a book and I have 2 issues. In the past, I used LaTeX because my books have some math in them. However, Amazon KDP rejected my last book on the premise that they cannot print the PDF that was generated from a LaTeX source. I tried all possible PDF tricks hoping they will accept the PDF but no luck.
This time I decided to use a different tool than LaTeX. After multiple tests, there are no perfect options. Writing in MS Word from scratch is not an option. I need sources so that I can work with publishers if needed. Asciidoc cannot render the inline math characters: they aren't aligned with the rest of the characters in the sentence in the PDF. So, I decided to work in markdown and then use pandoc to convert markdown to docx, and then docx to PDF if needed.
I managed to find various filters that implement the referencing of figures and equations, but I couldn't find anything for the following:
If I cannot solve these two issues, I will have to manually add the index and manually fix the figure alignment which is a problem because if I have to change the source markdown once again, I will have to fix the docx from scratch once again.
If anyone can help me here, I will be delighted.
Beta Was this translation helpful? Give feedback.
All reactions