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.

  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Commented Aug 26, 2013 at 9:02

1 Answer 1


Use a space Especially in math mode both {\foo} and \foo{} will have an adverse effect on spacing, and as you comment surrounding the command may negate it altogether, for example {\small} does nothing as the font change is discarded at the }.

  • 2
    Isn't it a bit more complicated? If the original was å finne then \aa finne produces the wrong output. So it depends on whether a space is wanted after the command or not. Commented Aug 26, 2013 at 10:22
  • @AndrewStacey for generated code I think it's easier to think of it as always terminating by a space, if you want to add a space you can add \ anyway \aa \ finne is OK Commented Aug 26, 2013 at 10:37
  • Having done some testing, I tend to agree with Andrew's comment. Maybe (at least in my case) using a terminating {} is an easier way to go since I work with a symbol-by-symbol transformation. Detecting whether an actual space follows a latex command would complicate the code to some degree. If the spacing in math mode (which is not a problem in my scenario) is the only caveat, I think I am fine with this solution.
    – MRA
    Commented Aug 26, 2013 at 12:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .