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 Answers
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}
\documentclass{article}
\usepackage{amsmath}
\mathchardef\mhyphen="2D % Define a "math hyphen"
\begin{document}
\newcommand\rnumber{\mathop{r\mhyphen number}}
\[
\rnumber(5) = 120
\]
\end{document}
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\newcommand\rnumber{\operatorname{r-number}}
\[
\rnumber(5) = 120
\]
\end{document}
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).
-
1Thank 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? 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– LSpiceJun 18, 2015 at 4:57
-
You should move the
\newcommand
s to the document preamble (before\begin{document}
). Aug 13, 2017 at 10:32 -
This is incredibly useful, thank you. I only needed
\mbox{\texttt{+-+-+-}}
.– mcpFeb 25, 2022 at 6:06
I think this is simpler.
$r{\text -}number(5)=120$
-
3Welcome to TeX.SX! Here some helpful information How do I write a good answer? Aug 13, 2017 at 10:29
-
3
-
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. May 20 at 6:54
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}
-
It seems that this solution does not work to typeset an r'-number: the ' becomes an apostrophe, rather than a prime.– BubayaOct 28, 2020 at 11:40
-
-
-
-
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.– BubayaOct 28, 2020 at 12:19
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.
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}
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.
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{ }}}
\text{r-number}
with packageamstext
loaded? I haven't used LyX though. Also check the symbols list at tex.ac.uk/tex-archive/info/symbols/comprehensive/symbols-a4.pdf.$r$-number
: only the $r$ is part of the formula; or else do you need the whole "r-number" inside a formula?\text{$F$-an}
?