9

I have a bunch of LaTeX snippets which I'd like to convert, as faithfully as possible, to Unicode strings.

(In fact, these are title of papers from a bibliographic database, which I'd like to use as filenames.)

Can anyone suggest how to 'compile' a snippet of LaTeX into plain text?

Here are some examples:

{\it {A}rithm\^etik\^e stoichei\^osis}꞉ on {D}iophantus and {H}ero of {A}lexandria
On a geometry of {I}vanov and {S}hpectorov for the {O}'{N}an sporadic simple group
On a theorem of {P}l\"unnecke concerning the sum of a basis and a set of positive density
On some series containing {$\psi(x)-\psi(y)$} and {$(\psi(x)-\psi(y))^2$} for certain values of {$x$} and {$y$}

My primary concerns are essentially just converting accented characters to unicode correctly and removing superfluous braces. I don't care about preserving formatting (e.g. \it above), and I'm happy leaving $ delimited math as is.

I'm interested in solutions that use TeX itself to do the conversion, as well as informed suggestions about doing the translation 'by hand' in some other language. Even removing braces, without destroying $ delimited math, seems tricky.

  • Why are some capitals wrapped in braces? – Tim N May 28 '13 at 11:26
  • have you considered using tex4ht? It'll turn your TeX into HTML, Word, etc. Might serve as an intermediate. – Nils L May 28 '13 at 11:46
  • 1
    @TimN As Scott says, they're titles from a bibliographic database. In BibTeX, if you wrap a capital in braces, it will be printed as a capital, regardless of whether the current setting is "all lower case" or "sentence case" or "title case" or whatever. – John Wickerson May 28 '13 at 11:50
13

Someone else will have to find a way to use 'TeX itself', which seems needlessly complicated, though admittedly not without interest. I prefer the philosophy of 'use the right tool for the job'. In this case, my advice is use pandoc, since this is what it was designed for: converting files from one markup to another. From exactly this input:

% latex-snippet.tex
\emph{{A}rithm\^etik\^e stoichei\^osis}꞉ on {D}iophantus and {H}ero of {A}lexandria % <-- fixed to use LaTeX syntax (\emph vs \it); seems to require extra blank line because of this comment


On a geometry of {I}vanov and {S}hpectorov for the {O}'{N}an sporadic simplegroup

On a theorem of {P}l\"unnecke concerning the sum of a basis and a set of positive density

On some series containing {$\psi(x)-\psi(y)$} and {$(\psi(x)-\psi(y))^2$} for certain values of {$x$} and {$y$}

You use:

pandoc -f latex -t plain -o outputfile.txt latex-snippet.tex

Result, as outputfile.txt:

Arithmêtikê stoicheiôsis꞉ on Diophantus and Hero of Alexandria

On a geometry of Ivanov and Shpectorov for the O’Nan sporadic simple group

On a theorem of Plünnecke concerning the sum of a basis and a set of positive density

On some series containing \psi(x)-\psi(y) and (\psi(x)-\psi(y))^2 for certain values of x and y

Off-topic addendum: It is better to wrap whole words in braces (e.g., {Diophantus}): it doesn't ruin any kerning between the letter in braces and the next letter, and it still preserves capitalization.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.