14

In contrast to \texttt{typewriter} normal text is "connected". When using a forward slash, I get for y/. this:

y/.

while I would like to get something like that:

y$!$/$!$.

which can be accomplished by y$\!$/$\!$., but this is brute-force. Is there a better way to tell LaTeX to "connect" the forward slash with the adjacent characters?

(For fractions there is \sfrac of the xfrac package, but I do not want to typeset fractions here.)

MWE:

\documentclass{minimal}
\begin{document}
y/.

y$\!$/$\!$.
\end{document}
5
  • It seems you want to draw the dot below the slash, so that their boxes will intersect. I'm not a pro typist so I might be wrong, but that seems beyond the scope of kerning.
    – T. Verron
    Nov 10, 2012 at 14:22
  • @T.Verron: Yes, and also to draw the slash next to the y, therefore their boxes overlap, too.
    – Stephen
    Nov 10, 2012 at 14:32
  • 1
    This should be better addressed by changing the kerning table for the font (but it would be a very hard job).
    – egreg
    Nov 10, 2012 at 17:22
  • 1
    What you want is essentially automatic kerning. This is obviously beyond the scope of TeX and it's really the font that should provide the kerning information anyway (otherwise you'd have to do one of the brute force methods described below which is ugly and not the point as you rightfully say). Automatic kerning is obviously not ideal in any case but even good fonts sometimes have crappy kerning tables for slashes and all caps. You can try the open source software FontForge which can do automatic kerning: fontforge.org/lookups.html#Pair and you can of course manually tune afterwards.
    – Christian
    Mar 5, 2013 at 13:49
  • @Stephen Upvoted because I needed something similar (N/A), and though it is "ugly", your solution got the job done.
    – DUO Labs
    Mar 3, 2021 at 21:07

2 Answers 2

7

use of \! may be brute force, but that is what is recommended in the texbook (examples, in math, on p.169; for plain tex, \! doesn't work outside of math, so a negative \kern would be needed).

if this tight spacing were always wanted, a font designer could provide kerning pairs between "y" and slash and between slash and period, but i suspect this is unlikely to be popular.

Update:
As reminded by @Stephen, "LaTeX News", Issue 32, TUGboat 41:3 (2020), p.290 announced that all spaces formerly defined in amsmath were moved to the kernel, and are usable in both math and text. These are

\,    \thinspace
\!    \negthinspace
\: \> \medspace
      \negmedspace
\;    \thickspace
      \negthickspace 
2
  • Yes, it is an exceptional case and the opposite to cases where automatic kerning between characters is not wished for and an {} between them is necessary. +1 and accepted. (Usually I would wait for some time before accepting, but when the TeXbook gives the answer...)
    – Stephen
    Nov 10, 2012 at 14:47
  • TUGboat, Volume 41 (2020), No. 3, says: "Spacing commands moved from amsmath to the kernel[:] Originally LaTeX only provided a small set of spacing commands for use in text and math; some of the commands like \; were only supported in math mode. amsmath normalized and provided all of them in text and math. This code has now been moved to the kernel so that it is generally available. (github issue 303) command name(s) \, \thinspace \! \negthinspace \: \> \medspace \negmedspace \; \thickspace \negthickspace "
    – Stephen
    Oct 15, 2021 at 18:15
3
\documentclass{minimal}
\makeatletter
\catcode`/\active
\def/{\@ifnextchar.{\@withdot}{\string/}}
\def\@withdot.{\ifmmode\!\string/\!
               \else\kern-1.8pt\string/\kern-1.8pt\fi.}
\makeatother

\begin{document}
y\slash.

y/.

$y/.$

\end{document}

enter image description here

4
  • OK, +1 also for this answer. y and . were just examples. My question should read "Whenever it is possible to overlap the boxes of the character before/after a forward slash without overlapping the character itself with the slash, reduce the space between character and slash as much as possible, leaving only a necessary space between, thus that the character and slash are recognized as separated." Just a little bit complicated...
    – Stephen
    Nov 10, 2012 at 15:17
  • 1
    @Herbert -- try this with g/. or q/.; the result is not so good. it really does depend on the shape of the character preceding the slash. Nov 10, 2012 at 16:53
  • @barbarabeeton: that is obvious ...
    – user2478
    Nov 10, 2012 at 17:07
  • @Herbert -- indeed obvious to you and me, but if someone uses it without thinking of the implications, and doesn't check the output, they might be called on the results by someone else reading it. just a suggestion to "think about it first". Nov 10, 2012 at 21:06

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.