2

How to type in XeLaTeX a symbol by its code? In particular, I am interested in different dashes:

U+2011 ‑ non-breaking hyphen as hyphen (U+2010), but not an allowed line break point

U+2012 ‒ figure dash as hyphen-minus, but has the same width as digits

U+2013 – en dash used e.g. to indicate a range of values

U+2014 — em dash used e.g. to make a break in the flow of a sentence

U+2015 ― horizontal bar used to introduce quoted text in some typographic styles; “quotation dash”; often (e.g., in the representative glyph in the Unicode standard) longer than em dash

Here is MWE:

\documentclass{article}
\usepackage{calc}
\newlength{\len}
\begin{document}

\textemdash\ \verb|\textemdash| = \setlength{\len}{\widthof{{\textemdash}}} \the\len\\
\textthreequartersemdash\ \verb|\textthreequartersemdash| = \setlength{\len}{\widthof{{\textthreequartersemdash}}} \the\len \\
\textendash\ \verb|\textendash| = \setlength{\len}{\widthof{{\textendash}}} \the\len \\

\end{document}

I tried \symbol{"2012} but it yields error.

3
  • Answer to this question works for me. Apparently, you have to use \usepackage{fontspec} and \setmainfont{Arial}. Of course, you can use any unicode font installed on your system
    – Alan Ford
    Oct 7, 2020 at 8:49
  • Hope this tex.stackexchange.com/questions/553091/… will helps you....
    – MadyYuvi
    Oct 7, 2020 at 8:52
  • 2
    I get no error if I add \symbol{"2012} to your MWE. I only get a missing character message as the default font doesn't have it. Oct 7, 2020 at 9:06

2 Answers 2

4

Using U+2013 as an example as they are all the same.

Just type the character directly.

^^^^2013

The ^^ notation (as in classic tex but extended to 4 or 6 ^) produces the character (as an input character) at the very earliest stage. So unlike following options can be used anywhere the character can be used eg \^^^^2013 is \–

\char"2013 (or latex \symbol{"2013} which expands to same).

This typesets as the character in the current font (if the font has that character)

\Uchar"2013

This expands to the character token. So can be used in expansion only contexts such as \typeout.

3

You can define yourself the names (I guess that TU should add these).

\documentclass{article}
\usepackage{fontspec}

\setmainfont{NewComputerModern}
\newfontfamily{\ebgar}{EB Garamond}

\newlength{\len}

% this is not even in xunicode
\DeclareTextSymbol{\textnbhyphen}{\UnicodeEncodingName}{"2011}
% this is in xunicode
\DeclareTextSymbol{\textthreequartersemdash}{\UnicodeEncodingName}{"2012}
% the following two are in tuenc
%\DeclareTextSymbol{\textendash}{\UnicodeEncodingName}{"2013}
%\DeclareTextSymbol{\textemdash}{\UnicodeEncodingName}{"2014}
% this is in xunicode
\DeclareTextSymbol{\texttwelveudash}{\UnicodeEncodingName}{"2015}

%%% easier input
\newcommand{\entry}[1]{%
  #1 & \texttt{\string#1} & \settowidth{\len}{#1}\the\len
}


\begin{document}

\noindent
\begin{tabular}{@{} l l l @{}}
\entry- \\
\entry\textnbhyphen \\
\entry\textthreequartersemdash \\
\entry\textendash \\
\entry\textemdash \\
\entry\texttwelveudash
\end{tabular}

\bigskip

\ebgar
\noindent
\begin{tabular}{@{} l l l @{}}
\entry- \\
\entry\textnbhyphen \\
\entry\textthreequartersemdash \\
\entry\textendash \\
\entry\textemdash \\
\entry\texttwelveudash
\end{tabular}

\end{document}

I used NewComputerModern because it has a richer supply of glyphs than Latin Modern; not full, as you see.

I concocted myself the name for U+2011, maybe there is a better one. Possibly there is a better name also for \textthreequartersemdash, maybe \textfiguredash.

enter image description here

You must log in to answer this question.

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