3

I'd like to print out two minus signs just after each other, like this -- (as in the C operator to subtract one). Doing -- gives one longer - sign. I've tried \char"2D\char"2D but that also just gives one longer - sign. How can this be done?

  • 5
    You can try -{}-, but maybe provide some more information about the context (math mode, verbatim, ...?) – Jasper Habicht Mar 29 '23 at 09:18
  • 3
    - in text is a hyphen not a minus sign. In math, $--$ does not ligature to a dash – David Carlisle Mar 29 '23 at 09:33
  • 4
    “as in the C operator” sounds like you try to add some kind of source code. In this case you should consider to add the source code verbatim or using a package like listings or minted, so -- wouldn't be a ligature any longer. BTW: Adding a minimal working example would help us to understand the question better and so to help you better. – cabohah Mar 29 '23 at 09:51
  • Thank you for the replies. Yes, I am writing C-code. I use \lstdefinestyle for larger blocks of code, but I've just changed the font when writing shorter snippets of code that resides within blocks of regular text. However, -{}- did the trick for now. – baldanders777 Mar 29 '23 at 13:02
  • 1
    There are certain monospaced fonts, such as Fira Code or Jetbrains Mono that come with special ligatures, for example for !=, -> and the like. -- might be part of such a set of ligatures. In this case -{}- would be a temporal workaround. A better way would probably be to disable the ligature in question. However, it depends on the font whether or not this is possible and, if yes, how to do this. – Jasper Habicht Mar 29 '23 at 14:45
  • 1

2 Answers2

9
\documentclass{article}
\begin{document}
$--$
-{}-
\verb|--|
\end{document}

enter image description here

Clara
  • 6,012
1

So I agree with the @Clara's answer but I want to explain the reasons or the workings a bit.

As you already may have noticed, - produces a single minus. This is the same minus which would be used in hyphenations.

Adding a second minus -- is the latex shortcut for an en-dash and --- produces an em-dash. Both of these are used to typeset interjected sentences -- like this one -- or abrupt stops.

In order to generate two separate minuses -- as in the above answer -- the command -{}- should be used. Here an empty scope is opened in between the two minuses. This stops LaTeX from joining them into an en-dash. The scope evaluates to nothing so there is no actual space added in between the minuses. The result is just two hyphenation-style minuses.

  • The above answer by @Clara (since the position on the page can change). \ In your actual answer (as opposed to your TeX code) you probably want your -- to be a Unicode ‘–’, but maybe the norm here on TeXSE is to use TeX formatting codes even when they aren't rendered. Anyway, grammatically I think you actually want an em dash ‘—’ or ‘---’ where you are using -- in text. (It's not exactly covered by the Wiki article, but self-interruption may come close.) \ There is a typo ‘hyphnation’. – LSpice Aug 05 '23 at 20:02
  • I updated my answer. However depending on where you live and what kind of aesthetic preferences you have, you may use either an en-dash or an em-dash. In Germany for example em-dashes are basically never used (but en-dashes with spaces around) whereas in the US it is common to use em-dashes (without spaces around) instead of en-dashes. – Oliver Leenders Aug 11 '23 at 10:31
  • 2
    Maybe to avoid confusion between hyphen and minus: - in text mode will actually print a glyph called "hyphen-minus" in Unicode. It is the glyph that is used in hyphenation, so, I typically prefer to call it a hyphen. There exists also a minus sign in some fonts which is a bit wider (as wide as a plus sign). In TeX, the equivalent to a minus is what would be typeset with $-$. – Jasper Habicht Aug 11 '23 at 11:00