TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing an AWK programming book and when I explain things, I refer to special AWK variables all the time, such as ORS. Is it possible to set LaTeX up in such a way that these words are always in bold in the text, so I don't have to write \bf{ORS} all the time?

share|improve this question
if these words do not exist as normal words in your document, then use search and replace with an external editor. ORS=>\texttt{ORS}. It is common to write program sequences in typewriter format. – Herbert Apr 30 '11 at 9:11
The question seems pretty similar to tex.stackexchange.com/questions/15626/… (which is still unanswered, though) – diabonas Apr 30 '11 at 10:17
Related Question: Possible CSS type features?. Although it may not be useful for entire documents, or large blocks of text. – Peter Grill Oct 11 '12 at 19:48
up vote 27 down vote accepted

For a job like this I usually define a convenience macro:


Now you can say \<ORS> without much overhead and still don't need to define macros for all the terms that are special. In the context of a book you might want to think about how this macro can be also used to create an index. (This is a little trickier and might warrant a separate question.)

share|improve this answer
@Christian According to this question isn't it better to use a /newcommand instead? – pmav99 Apr 30 '11 at 9:45
@pmav99 I believe you cannot use \newcommand to define a macro that uses TeX's pattern matching capabilities that I've used here to make the macro easier to use than regular macros. – Christian Lindig Apr 30 '11 at 9:47
Oh I got it now. You are using def because it allows you to use different delimiters. EDIT we wrote together. – pmav99 Apr 30 '11 at 9:48
@Yiannis This would preclude writing variable \*OFS, \*NF, and ... because the space to terminate the argument would be missing. I'd say, this is a matter of taste. – Christian Lindig Apr 30 '11 at 12:01
@pmav99 the xparse package allows you to have the flexibility of arbitrary pattern matching in delimiters with the safety of \newcommand – Seamus May 28 '11 at 17:22

In lieu of a ton of \newcommands, I would rather define a macro that stores a number of words for which you require them to be bold. This is simply a comma delimited list.

\def\boldcommandlist{\@elt FS,\@elt OFS,\@elt RS,\@elt ORS,\@elt NR,\@elt NF,\@elt FNR,}

Awk \OFS is an output equivalent of awk \FS variable. 
By default awk OFS is a single space character.
Following is an awk \OFS example. Use the command \OFS.


The \boldcommandlist holds the words to be typeset in bold:


You can always add another one if you wish at a later stage.

The \@elt is short for an element and is initially undefined. When we give it a definition, it picks up its argument as the next word (delimited by a comma) and creates a command for it. The xspace is a small package that correctly adjusts the spacing after a command catering correctly for such things as punctuation.

share|improve this answer
What does \makeatother do in your example? – Peteris Krumins Apr 30 '11 at 23:35
\makeatother changes the @ back to a symbol (category code 'other'). – Yiannis Lazarides May 1 '11 at 2:59

With LuaTeX, you can translate your input before it is passed on to TeX. Here is an example of doing the automatic translation in ConTeXt:


% Notice the space before the words
\translateinput [ OFS][ \bold{OFS}]
\translateinput [ FS] [ \bold{FS}]


Awk OFS is an output equivalent of awk FS variable. 
By default awk OFS is a single space character.
Following is an awk OFS example. Use the command OFS.

share|improve this answer
Does it work when OFS is at the beginning of a line in the source? – Andrey Vihrov Apr 30 '11 at 21:00
@Andrey. No :( The translate module translates all strings, so if I use \translate[OFS][...] even something like \startOFS will be translated. It should be possible to write a more intelligent pattern to check if the surrounding characters are non-letters and only do the substitution. – Aditya Apr 30 '11 at 21:49
@Aditya, I can't find any documentation for translate. (Actually, I always get confused navigating ConTeXt documentation in general, which I think says more about me than about ConTeXt.) Does it accept a regular expression to match, or only literal text? – L Spice Jun 15 '15 at 17:18
@LSpice: My understanding is that it was designed to show a proof of concept. It accepts only a literal match, but generalizing to regular expressions should not be difficult. It is just a 10 line function with some boilerplate code. – Aditya Jun 15 '15 at 21:06

First of all, try to avoid \bf{}, use \textbf{} instead. More info here, or search for the New Font Selection Scheme

you could use \newcommand{\ORS}{\textbf{ORS}\xspace} at the preamble, and invoke it in your document with \ORS. For \xspace usage look at the link in the comments


Compare \ORS with ORS.

Sentence ending in \ORS.


Updated the answer according to lockstep's suggestion.

share|improve this answer
By including a trailing space in your definition of \ORS, this macro can't be used before punctuation marks. Better approaches are a) using the xspace package b) using "delimited macros" -- see here for details. – lockstep Apr 30 '11 at 9:36
@lockstep Cool! I didn't know about xspace, although I knew that there must be a way to do it! – pmav99 Apr 30 '11 at 9:40

Combining Christian's answer with Yiannis, you can get a single \<...> markup which expands to different things (bold, italics,...) depending on the argument. It might be useful in some cases where you have different types of words to highlight.

\usepackage{hyperref}% used for an example.

\def\<#1>{\csname keyword@@#1\endcsname}

\def\keyword@style#1{#1\footnote{From the \<python> language.}}

I don't know what \<OFS> is, nor \<RS>, but they seem to be parts 
of the awk language. On the other hand, I know a little bit about 
\<try> and \<raise>. There are many packages about \TeX\ on the
\<CTAN> website.
share|improve this answer
That is really slick! +1 – Christian Lindig May 1 '11 at 5:52
@Christian. The number of extra characters to type could be reduced from 3 (\<, >) to 1 (an active character of your choice), but this would mean parsing the word one letter at a time until a non-letter is seens. Not too hard, but a little slower. – Bruno Le Floch May 1 '11 at 6:13
Knuth used |OFS| in the TeXbook by making | active and IMHO he does not rely on parsing letter by letter. Still two extra characters but I'd find the symmetry attractive. – Christian Lindig May 1 '11 at 6:36
@Christian. You are right, it is definitely simpler and faster to use two characters. – Bruno Le Floch May 1 '11 at 6:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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