TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

Is there a generally applicable technique which will, for any tag/environment used in a LaTeX document, allow the default styling of the contents of instances of that tag/environment to be tweaked in the preamble?

  • For instance, if I decided that all instances of \emph{} in the document should have their contents rendered not only italicised (a common default) but also bold, then what would I do?

  • Similarly, if I decided that all instances of \begin{verbatim}...\end{verbatim} should have their contents rendered not only in a monospaced font (a common default) but also on a grey background, then what would I do?

But more importantly than simply explaining how to handle these two example cases, please can you outline a procedure a LaTeX user can follow in all cases in order to be able to change the styling of any given tag/environment.

share|improve this question
These are really very different questions. There is no procedure that can work in all cases. – egreg Jul 4 '12 at 17:08
Just one example: \section has to do much more than a <head> tag in HTML, where, for instance, there's no problem with page breaking, widows and orphans. Comparing (La)TeX and HTML is really wrong. – egreg Jul 4 '12 at 17:42
OK, wrong example. But still there is no similarity between LaTeX and HTML, other than both use a kind of markup. – egreg Jul 4 '12 at 17:48
That's a pretty big similarity! Anyhow, I provided the analogy merely in case it helped anyone here see what I was getting at, not for any other reason. If it didn't help you, that's a pity, but it may yet help someone else. My question still stands. – sampablokuper Jul 4 '12 at 17:50
@egreg: In some sense one could argue that from a users point of view, LaTeX is similar to plain HTML 4 (without CSS (and hence <style>), JavaScript, etc.). Except of course that LaTeX automates many tasks (toc, ...). – Caramdir Jul 4 '12 at 18:38

Let's tackle only the first example. LaTeX declares \emph with


so we need to look up what \em does:

  \ifdim \fontdimen\@ne\font >\z@

The first instruction, \@nomath\em raises an error if the command is found in math mode, otherwise it does nothing. The conditional checks whether the current font is slanted (in this case \fontdimen1\font is positive); if so it issues \upshape, otherwise \itshape.

So, if you want \emph to choose "boldface italic" in an upright context and "upright boldface" in an italic context you have to say

  \ifdim \fontdimen\@ne\font >\z@

Is this a general method? No.

I won't even think to the changes necessary to print verbatim material on a grey background: the fancyvrb package provides such a feature and its code is very complicated.

In LaTeX you can't simply hand calls to the browser like HTML does. The two models are completely different.

share|improve this answer
I'm grateful for this, but although it addresses one of my examples, it doesn't really answer my question. How did you establish what LaTeX declares \emph (or any other command) to be? Why was this your first step? How did you look up what \em (or any other command) does? Where should the third code snippet you gave be put in order to apply to all instances of \emph in the present document? These are the sorts of things my question is getting at. – sampablokuper Jul 4 '12 at 18:11
@sampablokuper To look things up: \show\emph (etc.) in your document or texdoc source2e. – Caramdir Jul 4 '12 at 18:30

As egreg says there is no general way -- each one needs to be considered separately. So for the \emph you could redefine the command in the preamble:

enter image description here


  • As egreg pointed out, this required the use of \LetLtxMacro macro from the letltxmacro package instead of \let since \emph is declared with \DeclareRobustCommand.
  • As Caramdir pointed out this may or may not be what is desired for nested use \emph{}. This redefinition yields an alternating bold italic, with bold upright, where as the original definition yields an alternating non-bold italic, with a non-bold upright as shown above.




    \OldEmph{orignal emph}\par
    \emph{modified emph}\par
    \emph{modified emph with a \emph{nested emph}}
share|improve this answer
\emph is basically defined with \DeclareRobustCommand and it's quite dangerous to redefine it in this way (see the documentation of letltxmacro. – egreg Jul 4 '12 at 18:07
@egreg, but if letltxmacro were used instead of let then this approach would generally be OK? Or would there still be a danger - and if there is still a danger, then what would it be? – sampablokuper Jul 4 '12 at 18:19
@egreg: Thanks, I was mistaken in thinking that \LetLtxMacro was only required when there were optional parameters. Have updated the solution. – Peter Grill Jul 4 '12 at 18:22
This of course might or might not do what you intend when nesting \emphs. – Caramdir Jul 4 '12 at 18:35

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.