I've nothing to do with txfonts
(more exactly, txmi
family). Maybe you can use another Times like font package. mathptmx
works fine (but it has fewer symbols than txfonts
), and if you use XeTeX, you can also use XITS Math for math fonts. Commercial fonts like MathTimePro(2) are also good-looking.
I suggest XITS Math with XeLaTeX:
\documentclass{article}
\usepackage{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}
\begin{document}
See $S_1$, $S_2$, $S_3$.
\end{document}
\somefunction
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:
\ittt
Your original \ittt
was defined as
\newcommand*{\ittt}[1]{\textit{\texttt{#1}}}
\itttm
If you only use your entities in text mode before punctuation, \itttm
can work for you. It adds italic correction only in math mode.
\newcommand*{\itttm}[1]{%
\ifmmode\mmodebeforetrue\else\mmodebeforefalse\fi%
\textit{\texttt{#1\ifmmodebefore\/\fi}}%
}
\itttp
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{}}{%
\textit{\texttt{#1}#2\/}%
}
\ttit
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 ,
).
\newcommand*{\ttit}[1]{\texttt{\textit{#1}}}
\ttitc
Like \ttit
, but:
The if-macro \@ifnextchar
removes the italic correction before .
and ,
with a negative kern.
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
.
\entity[*]{<arg>}
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 ,
).
Conclusion
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).
Code
\documentclass{article}
\usepackage{times}
\usepackage{txfonts}
\usepackage{array,multirow,xcolor} % for presentation
\def\dont{\color[gray]{.5}} % *
\usepackage{xparse}% for \itttp and \entity
\newif\ifmmodebefore% for \itttm
\newcommand*{\somefunction}[1]{F(#1)}
\newcommand*{\ittt}[1]{\textit{\texttt{#1}}}
\newcommand*{\ttit}[1]{\texttt{\textit{#1}}}
\newcommand*{\itttm}[1]{% \itttc inserts italic correction \/ if in math mode
\ifmmode\mmodebeforetrue\else\mmodebeforefalse\fi%
\textit{\texttt{#1\ifmmodebefore\/\fi}}%
}
\makeatletter % needed because @ is used in macro name
\newcommand*{\ttitc}[1]{% \ttitc checks if . or , follows and kerns
\texttt{\textit{#1}}%
\@ifnextchar.{\kern-.1em}{\@ifnextchar,{\kern-.08em}{}}%
}
\makeatother
\DeclareDocumentCommand{\itttp}{m O{}}{% optional punctuation will be typeset italic
\textit{\texttt{#1}#2\/}%
}
\DeclareDocumentCommand{\entity}{s m}{% star = no italic correction (before , and .)
\textit{\texttt{#2}%
\IfBooleanTF{#1}%
{}%
{\/}%
}%
}
%\usepackage{lua-visual-debug} % use this with LuaLaTeX for debug-mode
\begin{document}\noindent
\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}. \\
\end{tabular}
\end{document}
Output
Best Answer
From this answer I got the solution to add
\mathitalicsmode=1
to the preamble. If I understand correctly, this enables italic correction in math mode. To obtain the desired result, one also has to remove the surrounding brackets{ ... }
, otherwise italic correction is not applied (except if there is a single character{f}
, then it seems to work. Why?) So the following code example works fine: