1

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).

atticus
  • 557
  • 1
    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? – Ulrike Fischer 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. – atticus 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? – atticus Nov 18 '20 at 13:44
  • 1
    @atticus The standard font does not contain this character. – Marcel Krüger Nov 18 '20 at 13:46
  • 1
    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. – Ulrike Fischer Nov 18 '20 at 13:46
  • I think especially for educational reasons I'd like to try this on my own. Are there any tricks on finding a font that supports these symbols? – atticus Nov 18 '20 at 15:20
  • Or if maybe someone could provide an Example for this case since at least I find it difficult to find some explanation on how to do this. – atticus Nov 18 '20 at 16:56

1 Answers1

4

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}

STIX 2 sample

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}

Computer Modern/STIX 2 sample

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.

Davislor
  • 44,045
  • First things first thank you very much for this help and I really appreciate it. I just have some questions left. The \Declare... commands will only affect the characters I set in \fontencoding{...} right? And one little question about the \DeclareUnicodeCharacter, this is basically just saying "whenever you encounter a character with this code, insert that macro" right? (maybe this is interesting when mapping special characters to custom macros, but I guess this would just cause confusion) – atticus Nov 19 '20 at 21:59
  • Oh and I just tried to look this symbol in the manual up, but I just found the Symbol in the Miscellaneous Mathematical Symbols-A section but found only the unicode again, not the Code 13 (the manual I looked into: https://ctan.kako-dev.de/fonts/stix2-otf/StixTwoMath.pdf) – atticus Nov 19 '20 at 22:08
  • 1
    @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. – Davislor Nov 19 '20 at 22:27
  • 1
    @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. – Davislor Nov 19 '20 at 22:31
  • This particular symbol is in slot 19 (hexadecimal "13) in the font named stix2frak But where do you read this, I found the symbol in https://ctan.kako-dev.de/fonts/stix2-otf/StixTwoMath.pdf (page 34) but there one can only read the Unicode. Or here http://vesta.informatik.rwth-aachen.de/ftp/pub/mirror/ctan/fonts/stix2-type1/stix2.pdf on pagr 41 the Character is labeled 0x23.

    – atticus Nov 21 '20 at 18:38
  • 1
    @atticus Page 41 of this manual Octal digits on the left. Hex on the right and bottom. – Davislor Nov 21 '20 at 18:45
  • 1
    @atticus By the way, unicode-math makes this so much easier. – Davislor Nov 21 '20 at 18:47
  • 1
    @atticus Whoops, sorry for the confusion! I told you to look in stix2-otf when I meant stix2-type1. My fault. – Davislor Nov 21 '20 at 18:49
  • Ok, thanks for all your explanation. Now I got from where the number came from. I'll have a look for unicode-math thanks for the suggestion (nevertheless I think it's interesting how to manually do this) – atticus Nov 21 '20 at 20:42
  • @atticus Oh, the difference isn’t doing it manually. With unicode-math, you use OpenType fonts and Unicode. The old-fashioned way like this, you use 8-bit fonts, and every package has a different code chart. – Davislor Nov 21 '20 at 22:23
  • @atticus Some publishers (notably the arXiv) only accept submissions that compile in legacy mode with PDFTeX. But my personal recommendation (which not everybody here agrees with) is to use unicode-math and LuaTeX when you can, and legacy fonts when you have to. – Davislor Nov 21 '20 at 22:25