# **LaTeX** insert Unicode Characters (relational Database chars)

I recently tried to insert the Characters for the relational Algebra (left/right (semi) join, ...) but failed up to now. I know that it is problematic with Unicode and ASCII encoding, but I thought with [utf8]{inputenc} it should work.

But

\documentclass{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\DeclareUnicodeCharacter{27d7}{⟗}

\begin{document}
⟗
\end{document}


does not work.

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.3 \DeclareUnicodeCharacter{27d7}{⟗}

? q
OK, entering \batchmode


is the font the problem or am I doing something wrong?

Oh and the nicest thing for me would be to know how to create a command \fullOuterJoin which inserts the character for me (easier than always copy the character).

• You are missunderstanding the command. The first argument contains the number of the char (in uppercase!) and the second argument should contain some code to type set it. So try \DeclareUnicodeCharacter{27D7}{hello-whatever}. And if you want a command, you need at first a font which has your glyph. Did you check the symbol list? Nov 18 '20 at 13:40
• Hm but when I take \DeclareUnicodeCharacter{27D7}{hello} and insert just hello into the document, just hello is printed. Nov 18 '20 at 13:44
• And regarding the symbol list, to be honest no I didn't how would this be done with the standard font? Nov 18 '20 at 13:44
• @atticus The standard font does not contain this character. Nov 18 '20 at 13:46
• exactly. That is how the command works. The symbol will print whatever you put in the second argument. The stix package has a \fullouterjoin symbol. You can either simply use the package (which will change more things), or define a command that switch to this font. Nov 18 '20 at 13:46

You want to look your symbol up in The Comprehensive LaTeX Symbols List, or one of the methods here. In this case, Ulrike Fischer found it for you and posted it in a comment: \fullouterjoin from stix (or also stix2).

The first argument of \DeclareUnicodeCharacter should have letters capitalized, so 27D4. The second argument should be the command to produce the character. That is, if you already have a command \fullouterjoin, you would use \DeclareUnicodeCharacter to turn the character ⟖ into a macro that runs that command.

In this case, \fullouterjoin is a math-mode command in stix and you want to want to use it in text mode, so \ensuremath{\fullouterjoin} will work.

\documentclass{scrartcl}

\usepackage[utf8]{inputenc} % The default since 2018
\usepackage[T1]{fontenc}
\usepackage{stix2}

\DeclareUnicodeCharacter{27D7}{\ensuremath{\fullouterjoin}}

\begin{document}
$$\textnormal{foo} ⟗ \textnormal{bar}$$
\end{document}


An alternative, which, unlike \DeclareUnicodeCharacter, works with LuaLaTeX or XeLaTeX, is newunicodechar:

\documentclass{scrartcl}

\usepackage[utf8]{inputenc} % The default since 2018
\usepackage[T1]{fontenc}
\usepackage{stix2}

\usepackage{newunicodechar}
\newunicodechar{⟗}{\ensuremath{\fullouterjoin}}

\begin{document}
$$\textnormal{foo} ⟗ \textnormal{bar}$$
\end{document}


Either of these had the disadvantage that, to load one symbol, you had to load the entire stix or stix2 package. There is no standard way to load only one symbol from a legacy TeX package, but here’s some code that will work in this case:

\documentclass{scrartcl}

\usepackage[utf8]{inputenc} % The default since 2018
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\DeclareFontEncoding{LS1}{}{}
\DeclareFontSubstitution{LS1}{stix2}{m}{n}
\DeclareFontFamily{LS1}{stix2frak}{\skewchar\font127 }
\DeclareFontShape{LS1}{stix2frak}{m}{n} {<-> stix2-mathfrak}{}
\DeclareFontShape{LS1}{stix2frak}{b}{n} {<-> stix2-mathfrak-bold}{}

\newcommand\textfullouterjoin{%
{\fontencoding{LS1}\fontfamily{stix2frak}\fontshape{n}\selectfont\symbol{"13}}}

\newcommand\fullouterjoin{%
\ifmmode\mathbin{\text{\textfullouterjoin}}%
\else\textfullouterjoin%
\fi}

\DeclareUnicodeCharacter{27D7}{\fullouterjoin}

\begin{document}
$$\textnormal{foo} ⟗ \textnormal{bar}$$
\end{document}


Since the manual for stix2-type1 has a font chart that says which slot of which font this symbol is in, I copied the relevant lines from the .sty and .fdd source files for the package, to set up the symbol font. I then wrote a command to either insert the glyph as a text symbol in text mode, or typeset it as a binary operator in math mode. (It therefore no longer needs \ensuremath.) Finally, I copied over the code from my first example to make the Unicode character expand to this command.

• @atticus I’m not sure I understand your question. Generally, fontenc will set up every character in the font encodings it loads.(There are some gotchas, such as how typing Cyrillic isn’t so easy because there’s more than one Cyrillic encoding.) You would use \DeclareUnicodeCharacter or \newunicodechar to set the others active and define what code they should expand to. Nov 19 '20 at 22:27
• @atticus In my last example, I need to select the font that contains the glyph by its family name, encoding and shape. (There is also a series parameter, m for medium or b for bold, but I leave that as-is.) This particular symbol is in slot 19 (hexadecimal "13) in the font named stix2frak, whose encoding is named LS1, with shape n for normal. Nov 19 '20 at 22:31
• @atticus Page 41 of this manual Octal digits on the left. Hex on the right and bottom. Nov 21 '20 at 18:45
• @atticus By the way, unicode-math makes this so much easier. Nov 21 '20 at 18:47
• @atticus Whoops, sorry for the confusion! I told you to look in stix2-otf when I meant stix2-type1. My fault. Nov 21 '20 at 18:49