52

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
    Jul 9, 2013 at 7:01
  • 1
    Here's what I use for "F-an" (meaning F-analytic) \text{$F\!\mbox{-}\mathrm{an}$} 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
    Jul 9, 2013 at 9:18
  • 1
    I need all of it inside the formula. It is the name of a function. Jul 9, 2013 at 9:28
  • 3
    @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
    Jun 18, 2015 at 4:53

6 Answers 6

30

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). Jul 9, 2013 at 17:33
  • what is "2D? Is that the character definition for hyphen? if so, where can I find others?
    – nlucaroni
    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
    Jun 18, 2015 at 4:57
  • You should move the \newcommands to the document preamble (before \begin{document}). Aug 13, 2017 at 10:32
  • This is incredibly useful, thank you. I only needed \mbox{\texttt{+-+-+-}}. Feb 25 at 6:06
36

I think this is simpler.

$r{\text -}number(5)=120$
1
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
    Oct 28, 2020 at 11:40
  • @Bubaya You can use r^{\prime}.
    – egreg
    Oct 28, 2020 at 11:46
  • Sure, but how about \operatorname{\mathnormal{r^2}-number}?
    – Bubaya
    Oct 28, 2020 at 12:04
  • @Bubaya \mathnormal{r}^2
    – egreg
    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
    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.

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
2

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.

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.