I am converting a document from LaTeX (XeTeX) to ReStructuredText using Pandoc. The document has a large number of index entries, and Pandoc does not handle indices. The index entries are stripped out when Pandoc converts, leaving just the text of the entry. So, what I need is a way to convert the index entries to ReST syntax in the LaTeX file before Pandoc strips them out upon conversion. In my tests, this sort of works: Pandoc preserves the index entries but escapes the backticks. I can strip those out. Here’s how it looks when I do it manually:
\index{Some index item} # The LaTex entry
:index:`Some index item` # Modified for ReST format (still in the LaTeX file)
:index:\`Some index item\` # Result after Pandoc conversion to ReST
I can replace the final escaped backticks with proper backticks in the final ReST file. What I can’t seem to figure out is how to create a workable method (Regex?) for the replacements in the LaTeX file. Suggestions most welcome (including suggestions about a better way to do this whole production).
It seems you are looking to replace entries that match the following regular expression
with
where
$1is a reference to the regex’s capture group([^}]*).You could automate this process with, for example, a shell script or do it manually in a text editor.
Note, the above regex assumes there is no
}inside the{}.