I am writing a LaTeX export feature for my database. To this end, I am doing a symbol-by-symbol transformation of special characters in latin-1 text fields to LaTeX macros, such as _
to \_
, ~
to \textasciitilde
, and so end. When doing this, many macro commands need to be separated from text immediately following it, or I will end up with errors like "~user
" being transformed to "\textasciitildeuser
".
Using Google I came up with a number of different ways to achieve this separation, such as:
- putting a white space at the end of the macro, e.g. '
\textasciitilde
' - putting an empty pair of brackets at the end, e.g. '
\textasciitilde{}
' - putting the macro into brackets, e.g. '
{\textasciitilde}
'
What is the correct an intended way to separate a LaTeX macro command from the text immediately following it? For instance, the third way seems a little problematic to me since putting stuff in brackets may have additional effect, e.g. when the text is used as content of BibTeX fields.
Any advise is appreciated.