I use txfonts and \texttt in italics in math mode, but the letters' italic correction is not working: an italic/"TT" letter "d" adjacent to a closing parenthesis touches it. Here is minimal sample code:


\newcommand*{\halfthinspace}{\kern .08333em} % not sure whether I got this value right
\newcommand*{\shorthalfthinspace}{\kern .06em}


\(\somefunction{\ittt{pd}}\) (what I get)

\(\somefunction{\ittt{pd}\shorthalfthinspace}\) (I want this)

\(\somefunction{\ittt{pd}\halfthinspace}\) (or this)

This is entity \ittt{pd}. (use of \verb|\ittt| within text; the spacing here is good)

\(\ittt{pd} \times \ittt{pd}\) (the space before the times symbol is minimally too thin)


To include additional space in the definition of \somefunction (\newcommand*{\somefunction}[1]{\textit{F}(#1\shorthalfthinspace)}) seems to be semantically the wrong approach. To include additional space in the definition of \ittt seems equally wrong, especially since I would occasionally like to use \ittt within text (see line 4 generated by my sample code) and don't want additional spacing before the sentence-final period. Finally, I may use \ittt in other contexts, such as around a \times operator (see line 5 generated by my sample code); the spacing doesn't only look too thin, it is too thin (easy to verify by turning the result by 180° in your viewer).

What it the easiest way to get appropriate spacing in all situations?

Note: I don't know whether this is an italic correction issue or something to do with \texttt or the structure of my macros. Feel free to improve the title of my question accordingly.

  • (tt stands for typwriter.) Why do use \textit in math mode? F(#1) would be typeset correct (and in italics) and uses the right spacing between F and (. Nov 7, 2012 at 3:06
  • 1
    Just an additional hint: There is the relative new package newtx. You should consider to switch over, take at least a closer look on it.
    – Speravir
    Nov 7, 2012 at 3:32

2 Answers 2



I have remove \textit entirely. In math mode variables (a-zA-Zα-ο) are usually typeset in italic shape. Math mode takes care of the italic correction (between F and ( in this case).
If you want to use \somefunction in text, use always inline math (\(…\)).

It wouldn't be that wrong to use a simple definition for the entity (pd) and “fix” the spacing inside \somefunction (or better: entityFunction/\funcOfEnt/…) except when parenthesized entities will be used more often and outside of a function, like (\entity{pd} + \entity{qr}) x, than the definition of the function should use the already patched \entity to be more consistent.

\textit and \texttt

I don't think there is a total automatic solution available for fixing the problem with ) and following punctuation.

Let's take a look at the options:


Your original \ittt was defined as



If you only use your entities in text mode before punctuation, \itttm can work for you. It adds italic correction only in math mode.



The macro \itttp typsets a second optional parameter in italic shape (but not in the typewriter family). This has been discussed on TeX.SE already.
In my eyes, this is even too tight.

\DeclareDocumentCommand{\itttp}{m O{}}{%


Switching \textit and \texttt gives us italic correction. But it also adds this italic correction before punctuation mark where you don't want it (i.e., . and ,).



Like \ttit, but:
The if-macro \@ifnextchar removes the italic correction before . and , with a negative kern.

\emph or \textit?

I also tested both variants with \emph:

  • \emph{\texttt{pd}} is a little better before ), and as good as \ittt before punctuation
  • \texttt{\emph{pd}} is as bad as \ttit.


I also declared another macro: \entity. It does exist in a non-starred and a starred form.
Use the starred form if you do not want italic correction (i.e. before . and ,).


I think the best solutions are:

  • \itttm if you need italic correction only in math mode.
  • \ttitc if can handle a few cases where the automatically inserted correction has to be re-corrected
  • \entity if you're willing to use a switch (the *) to toggle italic correction (it should be doable to use \@ifnextchar in \entity, too).


\usepackage{array,multirow,xcolor} %                       for presentation
\def\dont{\color[gray]{.5}} %                              *
\usepackage{xparse}%                                       for \itttp and \entity
\newif\ifmmodebefore%                                      for \itttm



\newcommand*{\itttm}[1]{%                                  \itttc inserts italic correction \/ if in math mode

\makeatletter %                                            needed because @ is used in macro name
\newcommand*{\ttitc}[1]{%                                  \ttitc checks if . or , follows and kerns

\DeclareDocumentCommand{\itttp}{m O{}}{%                   optional punctuation will be typeset italic

\DeclareDocumentCommand{\entity}{s m}{%                     star = no italic correction (before , and .)

%\usepackage{lua-visual-debug} % use this with LuaLaTeX for debug-mode
\begin{tabular}{l@{}c@{ }c@{ }c}
    macro                &              math               &              \verb|\times|              &               text                \\ \hline&             text mode             \\ \hline
    \verb|\ittt{pd}|     &         $(\ittt{pd} )$          &         $ \ittt{pd} \times {}$          &       \ittt{pd}, \ittt{pd}.       \\ \hline
    \verb|\itttm{pd}|    &         $(\itttm{pd})$          &         $ \itttm{pd} \times {}$         &      \itttm{pd}, \itttm{pd}.      \\
    \verb|\itttp{pd}|    &         $(\itttp{pd})$          &         $ \itttp{pd} \times {}$         &   \dont \itttp{pd}, \itttp{pd}.   \\
    \verb|\itttp{pd}[.]| &               ---               &                   ---                   &    \itttp{pd}[,] \itttp{pd}[.]    \\ \hline
    \verb|\ttit{pd}|     & \multirow{2}{*}{$(\ttit{pd} )$} & \multirow{2}{*}{$ \ttit{pd} \times {}$} &       \ttit{pd}, \ttit{pd}.       \\
    \verb|\ttitc{pd}|    &                                 &                                         &      \ttitc{pd}, \ttitc{pd}.      \\ \hline
    \verb|\entity{pd}|   &         $(\entity{pd})$         &        $ \entity{pd} \times {}$         & \dont   \entity{pd}, \entity{pd}. \\
    \verb|\entity*{pd}|  &               ---               &                   ---                   &    \entity*{pd}, \entity*{pd}.    \\



Output table

  • 1. I don't quite see an effect of \@ifnextchar.{\kern-.1em}{\@ifnextchar,{\kern-.08em}{}}. 2. I like the content of your writing very much (and I understand it I think), but could you expand it a bit with prose? Nov 7, 2012 at 9:54
  • @user14996 I've updated (read: overhauled) my answer. Hopefully it is more understandable now. The effect of \@ifnextchar is visible when you compare \ttit and \ttitc. Nov 7, 2012 at 20:25
  • Is there a way to have the correction of \ttitc work if the macro is within macro but the following punctuation outside? Nov 20, 2012 at 18:24
  • @user14996 So that {\ttitc{pd}}. works as {\ttitc{pd}.}? I suppose this is doable, but I don't know how, though. Why can't you put the punctuation inside the outer macro? Anyway, I suggest asking a separate question as this isn't related to italic corrections. Nov 20, 2012 at 19:25
  • I meant (maybe this is what you have in mind too) that I may write something like \([...] \ttitc{pd}\). and would like italic correction to apply nonetheless. Nov 20, 2012 at 20:24

If \texttt and \textit are exchanged, then the italics correction is inserted. Also in the example, \textit is only applied to F if not in math mode.


  \ifmmode\else\expandafter\textit\fi F(#1)%








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.