63

In a LyX math formula, I want to write something like "r-number". However, the usual dash looks too long (like a minus sign). I am looking for a short, possibly upper hyphen. I couldn't find it in the lists of symbols in the bottom toolbar, and I also don't know how to search for symbols online If you can give me a tip, how to find a symbol that I need, this will be very useful.

6
  • 4
    Can't we use \text{r-number} with package amstext loaded? I haven't used LyX though. Also check the symbols list at tex.ac.uk/tex-archive/info/symbols/comprehensive/symbols-a4.pdf.
    – Jagath
    Commented Jul 9, 2013 at 7:01
  • 1
    Here's what I use for "F-an" (meaning F-analytic) \text{$F\!\mbox{-}\mathrm{an}$} Commented Jul 9, 2013 at 7:27
  • The right way to type this is $r$-number: only the $r$ is part of the formula; or else do you need the whole "r-number" inside a formula?
    – egreg
    Commented Jul 9, 2013 at 9:18
  • 2
    I need all of it inside the formula. It is the name of a function. Commented Jul 9, 2013 at 9:28
  • 5
    @LaurentBerger, that seems like an awful lot of work to subvert LaTeX's understanding of what is math and what is text. Why not \text{$F$-an}?
    – LSpice
    Commented Jun 18, 2015 at 4:53

6 Answers 6

33

Here are three suggestions. The first is my own, and the second and third are adapted from (http://www.logic.at/staff/salzer/etc/mhyphen/). Note that the first and second both output "math italic" text, but the third outputs "upright" text.

\documentclass{article}
\begin{document}
\newcommand\rnumber{\mathop{\mbox{$r$-$\mathit{number}$}}}
\[
\rnumber(5) = 120
\]
\end{document} 

enter image description here

\documentclass{article}
\usepackage{amsmath}
\mathchardef\mhyphen="2D % Define a "math hyphen"
\begin{document}
\newcommand\rnumber{\mathop{r\mhyphen number}}
\[
\rnumber(5) = 120
\]
\end{document} 

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\newcommand\rnumber{\operatorname{r-number}}
\[
\rnumber(5) = 120
\]
\end{document} 

enter image description here

LyX users should put the definitions (\usepackage, \newcommand, \mathchardef, etc.) in Document -> Settings -> LaTeX Preamble, and the usage (e.g. \rnumber(5) = 120) inside math-mode (Ctrl+M).

5
  • 1
    Thank you! I edited to add a note for LyX users (such as myself). Commented Jul 9, 2013 at 17:33
  • what is "2D? Is that the character definition for hyphen? if so, where can I find others?
    – nlucaroni
    Commented Nov 8, 2013 at 19:39
  • @nlucaroni, it is just the ASCII code in hexadecimal: see en.m.wikipedia.org/wiki/ASCII#ASCII_printable_code_chart
    – LSpice
    Commented Jun 18, 2015 at 4:57
  • You should move the \newcommands to the document preamble (before \begin{document}). Commented Aug 13, 2017 at 10:32
  • This is incredibly useful, thank you. I only needed \mbox{\texttt{+-+-+-}}.
    – mcp
    Commented Feb 25, 2022 at 6:06
60

I think this is simpler.

$r{\text -}number(5)=120$
3
  • 3
    Welcome to TeX.SX! Here some helpful information How do I write a good answer?
    – Bobyandbob
    Commented Aug 13, 2017 at 10:29
  • 3
    Best answer here.
    – alelom
    Commented Jul 18, 2022 at 16:03
  • The braces serve no purpose, \text already makes an ord atom. (The "proper LaTeX" usage would be \text{-}, but TeX does not really care if you put single-letter macro arguments in braces. In fact, the space is also redundant, it can be just \text-.) And it should be \mathit{number} to make kerning correct. Commented May 20, 2023 at 6:54
14

My first shot would be \DeclareMathOperator; but it depends on the meaning of "r": if it represents a math variable it should be in italics. I'll show both possibilities, take your pick.

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\rnumberA}{r-number}
\DeclareMathOperator{\rnumberB}{\mathnormal{r}-number}

\begin{document}

$\rnumberA(2)$

$\rnumberB(2)$

\end{document}

enter image description here

7
  • It seems that this solution does not work to typeset an r'-number: the ' becomes an apostrophe, rather than a prime.
    – Bubaya
    Commented Oct 28, 2020 at 11:40
  • @Bubaya You can use r^{\prime}.
    – egreg
    Commented Oct 28, 2020 at 11:46
  • Sure, but how about \operatorname{\mathnormal{r^2}-number}?
    – Bubaya
    Commented Oct 28, 2020 at 12:04
  • @Bubaya \mathnormal{r}^2
    – egreg
    Commented Oct 28, 2020 at 12:17
  • Sorry, my comment was apparently too short to make my point. If I write \newcommand{\Mod}[1]{\operatorname{\mathnormal{#1}-Mod}}, things like \Mod{A_2} fail.
    – Bubaya
    Commented Oct 28, 2020 at 12:19
10

To define a hyphen for use as part of a hyphenated name in a macro, I used the command \def\mymathhyphen{{\hbox{-}}}. This gives the usual en-dash.

4

Another beautiful dash defined as a symbol. Short and simple.

\documentclass{article}

%Defining my short hyphen with name \mhyphen
%as an ordinary (\mathord) math symbol.
\DeclareMathSymbol{\mhyphen}{\mathord}{AMSa}{"39}

\begin{document}
$r\mhyphen number(t)$
\end{document}

enter image description here

Advantages:

  • No extra packages needed.
  • No need to change from math to text mode.
  • The whole expression r-number(t) needs not be redefined as operator, i.e., \mathop or similars. It affects spacing in formulae.
3

Yet another way to create a dash is to use a strike-out through a space.

It creates a slightly longer one than given in the answer by Sam Buss, which is what I needed. One could define the macro by

\usepackage[normalem]{ulem}
\newcommand{\mydash}{\hbox{\sout{ }}} 
0

You must log in to answer this question.

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