# - - - t e x i f y def texify(rawEng): '''Mark up an English name for TeX. [ if rawEng contains both an even number of double-quotes and an even number of underbars -> return rawEng marked up for TeX else -> raise ValueError ] '''
This function performs two substitutions:
") characters are converted
to the TEX convention. Even-numbered occurrences are
"``", and odd-numbered
"''". See Section 5.11, “
TEX_LQ” and Section 5.12, “
We use an instance of Section 10.10, “
class Texer: State machine for TEX
perform these substitutions.
#-- 1 -- # [ texer := a new Texer instance in non-quotes, non-italic # state ] texer = Texer() #-- 2 -- # [ result := rawEng, with its double-quotes and underbars # converted according to the state of texer # texer := texer with its state modified according to the # number of double-quotes and underbars in rawEng ] result = ''.join ( [ texer.convert(c) for c in rawEng ] )
If quotes and underbars were balanced,
should be in its initial state. Otherwise it's an error.
#-- 3 -- if texer.italics: raise ValueError("Unbalanced underbars: '%s'" % rawEng) if texer.quotes: raise ValueError("Unbalanced double-quotes: '%s'" % rawEng) else: return result