I need to use Bold or Italic a particular word through my latex document, where ever it is used, without explicitly mentioning textbf{} and textit{} on each of them. How can I do that?

A good analogy would be, CSS to HTML tags.

Is it possible to this in Latex?

  • \newcommand{\mystrangeword}{\textbf{particularword}\xspace} for example, use \mystrangeword then. -- and yes, \xspace has its issues ;-) – user31729 Oct 7 '15 at 15:41

Here is \mymarkup in a starred and unstarred variant. The unstarred variant gives \textbf{...} and the starred one is responsible for italic version. The double starred version gives bold and italic and the optional parameter changes the text:



      {\bfseries\itshape #3}%

\mymarkup\ is better than \mymarkup*\, which is followed by \mymarkup**\ again

\mymarkup[Don't use xspace]\ is better than \mymarkup*[Don't use xspace]\, which is followed by \mymarkup**[Don't use xspace]\ again


enter image description here


If it's a similar word each time you can create a command:


Another solution is to create shorter tag for \textbf or \textit:


Those solutions suppose that you have no particular command called the same way or an error will be raised.

  • \xspace... ;-) – user31729 Oct 7 '15 at 15:43
  • @ChristianHupfer keyboard doesn't want to work all the time ;-) – Romain Picot Oct 7 '15 at 15:44
  • 2
    \i and \b are defined commands already – user31729 Oct 7 '15 at 15:49
  • Oh no! An xspace! – yo' Oct 7 '15 at 15:51
  • @yo' A wild xspace appears. xspace used \xspace, it’s super effective! – moewe Oct 7 '15 at 16:03

Just for variety, here's a LuaLaTeX-based solution. Note that it doesn't require you to modify the body of the document in any way. The word to be rendered in bold-italics throughout the document should be listed as the second argument of the string.gsub function.

enter image description here

% !TEX TS-program = lualatex

function highlight_word ( line )
   return string.gsub ( line, "myparticularword", "{\\bfseries\\itshape %0}" )
luatexbase.add_to_callback ( "process_input_buffer", highlight_word, "highlight_word" )

An interesting story about myparticularword and its history \dots
  • You're into lua recently, hm??? ;-) – user31729 Oct 7 '15 at 15:58
  • @ChristianHupfer - Yup, you got me pegged... – Mico Oct 7 '15 at 15:58
  • 1
    I got you pegged? What have I done? :D – user31729 Oct 7 '15 at 16:02

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.