4

When formatting object dot notation ("x.next") in math mode I want to combine a math-mode variable (x) with a field name (next), separated by a period. For this I've been using code $x.\textit{next}. LaTeX, however, makes the spacing look poor depending on the variable name preceding the field. With a variable named "f" it looks quite bad f.next. Adding negative space helps, but the amount of negative space needed to fix it seems to depend on the variable itself. For example, one \! is not quite sufficient for "f" enter image description here, but two looks ok enter image description here, whereas if the variable name is "e" one is a little tight but maybe ok enter image description here, and two is quite bad enter image description here.

Putting both the variable and the field name in the \textit works, but the font for the variable name is then different from normal made mode, so that's not a solution. Is there any way to fix the spacing between the variable and the period, without needing to make separate macros for each different variable name?

2
  • Wecome to TeX.SX! What prevents you from using \textit{f.next}? I would probably not typeset such things in italics, but this might be a matter of taste. Nov 10, 2022 at 13:49
  • Thanks. Single-letter variables I've typeset in regular math mode throughout, and the font is slightly different between math-mode and \textit, so mixing $f$ and \textit{f.next} makes the "f"s look like subtly different symbols. I'd really rather not have to change every single variable use to \textit just to accommodate the few places where object notation is used. Nov 10, 2022 at 14:05

1 Answer 1

5

I'd use a command for this and compensate using the italic correction of the math italic symbol.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\sv}[2]{% subscripted variable
  #1%
  \kern-\fontcharic\textfont1`#1 %
  \mathit{.#2}%
}

\begin{document}

$\sv{f}{next}+\sv{e}{next}+\sv{y}{next}$

\end{document}

enter image description here

3
  • Thanks, that seems to work nicely! Nov 10, 2022 at 14:17
  • @UsingLatexForCode Don't use it for other than Latin letters.
    – egreg
    Nov 10, 2022 at 15:14
  • Thanks, yes, I noticed that too. :) Still amply sufficient in my case. Nov 10, 2022 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .