7

I'm forced to work with latex, and want to make use of unicode chars in math. So I write:

\documentclass{article}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{B7}{\cdot}
\usepackage[mathletters]{ucs}
\begin{document}
$a · b$
\end{document}

But it gives:

aΔb

Is there a way to DeclareUnicodeChars after ucs?


The ucs manual has something to say about DeclareUnicodeChars:

Several options have a special hardcoded meaning:
...
Every character you define in your document using \DeclareUnicodeCharacter
has the option document. This option is activated per
default having the priority 1000, therefore manually declared characters take
precedence over all other characters, unless some other option has explicitly
gotten a higher priority.
...

So I tried the way I understood it:

\DeclareUnicodeCharacter[document]{B7}{\cdot}

and

\DeclareUnicodeCharacter{B7}[document]{\cdot}

but it doesn't work.


Also tried:

\DeclareUnicodeOption{document}

and it also doesn't work.

Edit:

\documentclass{article}

\usepackage[mathletters]{ucs}

\usepackage[utf8x]{inputenc}

\begin{document}
\DeclareUnicodeCharacter{00B7}{\cdot} % U+00B7 = cdot
$a · b$
\end{document}

Gives:

! Missing = inserted for \ifnum.
<to be read again> 
                   B
l.10 \DeclareUnicodeCharacter{00B7}{\cdot}
                                           % U+00B7 = cdot

Also after reading ucs sources I tried:

\documentclass{article}

\usepackage[mathletters]{ucs}

\usepackage[utf8x]{inputenc}

\uc@dclc{183}{mathletters}{\ensuremath{\cdot}}%·

\begin{document}
$a · b$
\end{document}

but it gives:

! Undefined control sequence.
l.7 \uc
       @dclc{183}{mathletters}{\ensuremath{\cdot}}%·
Adobe
  • 3,037

3 Answers3

9

Life is much easier without ucs:

\documentclass{article}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{00B7}{\cdot}

\begin{document}
$a · b$
\end{document}

But with ucs you simply have to use the correct decimal:

\documentclass{article}
\usepackage[mathletters]{ucs}
\usepackage[utf8x]{inputenc}
\DeclareUnicodeCharacter{183}{\cdot}

\begin{document}
$a · b$
\end{document}
Adobe
  • 3,037
Ulrike Fischer
  • 327,261
  • 1
    Yep -- probably it's not hard to define all the chars by hand. – Adobe Aug 13 '13 at 10:09
  • 3
    @adobe ucs works too see my edit, but I don't like it. It does everything a bit different than the standard inputenc and you never know if it will clash with some package (like biblatex). – Ulrike Fischer Aug 13 '13 at 10:11
  • 2
    The second code does not work anymore (I noted this after a release_upgrade from Ubuntu 18 to Ubuntu 20 with accordingly updated TeX versions)? \DeclareUnicodeCharacter seems to be an undefined contrl sequence in this combo. Removing any of the three preamble lines compiles with warnings (and perhaps not the desired result) – Hagen von Eitzen Jan 11 '21 at 17:34
  • @HagenvonEitzen well as I wrote: it is easier without ucs. Simply don't use it, it is not compatible with everything (and not really maintained). – Ulrike Fischer Jan 11 '21 at 17:43
8

Life is even easier with newunicodechar:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{newunicodechar}

\newunicodechar{·}{\cdot}

\begin{document}
$a·b$
\end{document}

If you want to retain the default definition (\textperiodcentered) in text mode, then type

\newunicodechar{·}{\ifmmode\cdot\else\textperiodcentered\fi}
egreg
  • 1,121,712
2

For the last example you could use makeatletter and makeatother. See latex2e.pdf for documentation of those commands.

The second code does not work anymore (I noted this after a release_upgrade from Ubuntu 18 to Ubuntu 20 with accordingly updated TeX versions)? \DeclareUnicodeCharacter seems to be an undefined contr[o]l sequence in this combo. Removing any of the three preamble lines compiles with warnings (and perhaps not the desired result)

Source: a comment

In such cases, this solution will still work.

Not that I recommend using this package (see package comparison: utf8x vs. utf8 (inputenc)), but there are some issues about normal utf8 that I'm figuring out.

%! TEX program = pdflatex
\documentclass{article}
\usepackage[mathletters]{ucs}
\usepackage[utf8x]{inputenc}

\makeatletter \uc@dclc{183}{mathletters}{\ensuremath{\cdot}}%· % use {default} instead of {mathletters} to make it work in e.g. text mode \makeatother

\begin{document} $a · b$ \end{document}

user202729
  • 7,143
  • utf8 is actively maintained by the LaTeX team and has a GitHub site for submitting issue reports. On the contrary, nobody has touched ucs for several years. – egreg Oct 26 '21 at 08:58
  • Without knowing the TeX Live version that's deployed, it's impossible to give advice; \DeclareUnicodeCharacter is defined in the kernel starting at least from 2018-04-06. For previous releases, you need \usepackage[utf8]{inputenc}. – egreg Oct 26 '21 at 13:22