# How can I call unicode characters in LaTeX or LyX?

The only way I know to use Unicode characters in LaTeX involves another program such as Word.

I'll discuss an example, the inexact differential symbol đ. U+0111 is đ, so in Word typing 0111 followed by Alt-X returns đ. I can then copy đ into a .tex or .lyx document. However, if there's anything analogous to Word's Alt-X trick, at least in LyX (which I use), that would be convenient.

• A warm welcome to TeX.SE! – A Feldman Jun 4 '16 at 12:40
• What is your OS? Windows? – Ulrike Fischer Jun 4 '16 at 12:47
• This is not a mathematical symbol, but LATIN SMALL LETTER D WITH STROKE – egreg Jun 4 '16 at 14:26
• @egreg It may have been invented for non-mathematical reasons, but it's used for inexact differentials, e.g. in thermodynamics. – J.G. Jun 5 '16 at 9:16

You could do this from the menus with LyX. Use:

Insert > Special Characters > Symbols,...

And get this pop-up window:

And input your symbol that way (like Word's ALT-I, if memory serves). You then can copy/paste if you want to keep using that symbol.

You can also use the "Evil Red Text" technique as noted by @AFeldman. If you use that approach, though, you will get the raw code in your LyX window, rather than the actual character (using đ = U+0111 = dec 273):

which produces:

I find it helpful to see the character! If you only use a few characters like this, you can create key bindings for them. Or if they appear in some national keyboard layout, you can also set these up as "languages" in LyX, and use the OS's keyboard driver for input.

• The effect of \char is related to the encoding of the fonts and so can change if is you e.g. change the engine or the fontencoding or switch to math. Beside this \char273 e.g. will not work with pdflatex. I wouldn't use this as an input method except in a emergency. – Ulrike Fischer Jun 4 '16 at 14:20

The character U+0111 is not a math symbol. There is no symbol for the inexact differential in Unicode, as far as I know.

I suggest defining a macro for it:

\documentclass{article}

\newcommand{\diff}{\mathop{}\!d}
% http://tex.stackexchange.com/a/253108/4427
\newcommand{\dbar}{{\mkern3mu\mathchar'26\mkern-12mu d}} %
\newcommand{\idiff}{\mathop{}\!\dbar}

\begin{document}

$f(x)\diff x+g(y)\idiff y$

\end{document}


If you need the “d” to be upright, you can slightly modify the code

\documentclass{article}

\newcommand{\diff}{\mathop{}\!\mathrm{d}}
% http://tex.stackexchange.com/a/253108/4427
\newcommand{\dbar}{{\mkern2mu\mathchar'26\mkern-11mu \mathrm{d}}}
\newcommand{\idiff}{\mathop{}\!\dbar}

\begin{document}

$f(x)\diff x+g(y)\idiff y$

\end{document}


Go to View > Toolbars > Command Buffer or do Alt + x (may depend on your OS, this works on Ubuntu). Go down to the bottom where a text box appeared and enter unicode-insert 0111 and then press return. LyX will take care of the rest. If you do this in plain text, LyX inserts \dj{} for you. If you do this in math, LyX inserts $\mkern3mu\mathchar'26\mkern-12mu d$ for you.

A bit of technique first. LyX is based on Qt, and Qt delegates the input of Unicode character to input to a component called the Input Method. This includes typing the code point directly, as stated here: https://bugreports.qt.io/browse/QTBUG-8. Thus LyX receives the Unicode character directly in interpreted form from the Input Method. In particular what applies to other applications applies to LyX.

For instance, on Linux there is the input method IBus-LaTeX that lets one enter Unicode symbols in the LyX window (including mathematical symbols that LyX itself does not know) by entering its name in LaTeX (or XeTeX), which some may find more convenient than learning the code points. But the following page shows a similar software for entering the character with Ctrl+Shift+U followed by the code point (Linux still): https://wiki.lyx.org/Tips/UnicodeInputUsingCtrl-Shift-U.

Windows

Knowing this, it is easy to find information about what the solution could be on Windows: http://www.fileformat.info/tip/microsoft/enter_unicode.htm. This page suggests several methods, the most likely to succeed being:

1. Hold Alt, then press + (numerical keyboard), then type the hexadecimal code, and release Alt. This may require editing the regisry and setting EnableHexNumpad to "1" under HKEY_Current_User/Control Panel/Input Method (with type REG_SZ).

2. Use the Unicode Input Method Editor. It is enabled by setting a language such as Chinese - Unicode in the Regional Settings, and it triggers with the key LeftAlt Shift followed by the hexadecimal code.

If none of the methods above work, it might be a sufficient reason to fill in a bug report at http://www.lyx.org/trac/wiki/BugTrackerHome.

Epilogue

Finally, LyX converts the Unicode code points into commands understood by LaTeX. But since LaTeX does not handle many different characters, LyX could warn that certain characters are unencodable in LaTeX. One must then switch to XeTeX or LuaTeX by checking “Use non-TeX fonts” in the document preferences.

∻∻∻

That being written, for the use that you suggest, you are probably better off defining a Math Macro once and for all and type it by its custom LaTeX command name directly in LyX's math mode.

For the record: in Linux, with Lyx (or without Lyx):

• Alt Gr + D = ð
• Alt Gr + F = đ

To use the unicode character in math mode you can use \text{đ} or \text{\textit{đ}} of amsmath package:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\begin{document}
$f(x) \mathop{\!}dx+g(y)\mathop{}\text{\textit{đ}} y$
$f(x) \mathop{\!}dx+g(y)\mathop{}\text{đ} y$
\end{document}


To enter a character in LyX you can use the "Evil Red Text" (Ctrl-T)to enter a \char and the ascii number. For instance \char126 usually produces a tilde "~". You have to know what your character map produces.

• With 2.2.0 on this Mac it's ⌘-L. FWIW. – Dɑvïd Jun 4 '16 at 13:24