2

I am wondering if there is a generally preferred way to write words with - in formula.

For example:

$k-distance$

or

$k \textit{-} distance$

of maybe something better?

  • $k$-distance. Only the k should be in math mode. – Peter Grill Dec 11 '15 at 9:10
  • even inside equations? Suppose $k-distance(p)$ How should I write it? – Donbeo Dec 11 '15 at 9:11
  • never use math italic for words, the font is designed to make adjacent letters not look like a word, also - will be a minus sign if you set it in math, and you need a hyphen. In display math use \textrm{$k$-distance} – David Carlisle Dec 11 '15 at 9:13
  • I think it depends on what distance denotes? Is it a function? ... Or just go with David's recommendation. He know far more than I do. – Peter Grill Dec 11 '15 at 9:15
4

You seem to be using this as an operator, so let AMS take care of fonts and spacing:

enter image description here

Some possibilities:

\documentclass{article}

\usepackage{amsmath}

\DeclareMathOperator\kdista{\text{$k$-distance}}
\DeclareMathOperator\kdistb{\text{$k$-distance}}
\DeclareMathOperator\kdistc{\mathnormal{k}-distance}% I'd use this

\begin{document}


$\kdista(p)$ {\itshape $\kdista(p)$}


$\kdistb(p)$ {\itshape $\kdistb(p)$}


$\kdistc(p)$ {\itshape $\kdistc(p)$}

\end{document}

In general never use math italic for words, the font is designed to make adjacent letters not look like a word, also - will be a minus sign if you set it in math, and you need a hyphen.

For one-off use if you do not want to define an operator or use amsmath, or you need k to refer to a math italic k you could use \textrm{$k$-distance}

  • thanks an additional question. I have the equation in a \newtheorem{definition}{Definition}[section] where every words is in italic. If I use textrm then distance is written in italic as well. While if I use DeclareMathOperator k is not in math mode. – Donbeo Dec 11 '15 at 9:21
  • I believe k should be a mathnormal k... – yo' Dec 11 '15 at 9:21
  • ok best solution is probably \DeclareMathOperator\kdist{\mathit{k}-distance} – Donbeo Dec 11 '15 at 9:23
  • @Donbeo no \mathit gives the text italic k not math italic, if you want an operator using math k I'll add to my question... – David Carlisle Dec 11 '15 at 9:24
  • 1
    @Donbeo with reference to your first comment. it is by design that math operators do not pick up the surrounding text font stye. It is quite common for fonts in math to have different meanings and a scalar should not turn into a vector for example just because the surrounding text is bold. – David Carlisle Dec 11 '15 at 9:26

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.