# How to input characters into XeLaTeX

How do I input the non-keyboard characters into TeXShop?

My minimum working example:

\documentclass{book}
% Font Settings
\usepackage{fontspec}
\newfontfamily\myfont{C64 Pro Mono}
\begin{document}
\myfont\huge
Commodore 64 Font\par
\normalfont
Normal Font\par % Book title
\end{document}


The text "Commodore 64 Font" appears in the C64 Pro Mono font like I want, but I can't figure out how to get the other characters (see picture) beyond what I can type on the keyboard.

I'm using a Mac, so I can find the codes for the other characters through the Characters app, but I don't know how to get them into TeXShop. If I cut-and-paste, then I get strange characters.

I'm assuming there is a way to put the Unicode in, but I can't figure out how.

I've seen examples where non-English language is input - CJK, etc. - but TeXShop doesn't seem to allow it for me.

Edited to add:

I've found the glyph codes in Character viewer based on the answer below, so I'm adding a picture here in case anyone else is looking for a way to find the glyph numbers for use with \XeTexglyph :

-
Unfortunately this only works with the pre-Lion version of the character viewer. Since Lion, the character viewer no longer allows you to see all the characters for one particular font. –  Alan Munn Aug 13 '13 at 14:03

## 2 Answers

Another way to enter the characters is to enter them directly with the \XeTeXglyph macro or use their Unicode character code using the \char macro.

For example, the heart symbol is Unicode 2665 so you can enter that using:

\char"2665


It's also possible to use the font specific glyph index number. For a font like the C64 font, which doesn't have a huge character inventory, this might be easiest. The following document creates a full font table for the C64 Pro Mono font (the upper bound was found by trial and error, but you could use FontForge to find the total number of glyphs as well).

% !TEX TS-program = xelatex

\documentclass[12pt]{article}
\usepackage{pgffor}
\usepackage{fontspec}

\newfontfamily\csixtyfour{C64 Pro Mono}

\DeclareTextFontCommand{\textcom}{\csixtyfour}
\begin{document}
\parindent=0pt
\foreach \x in {4,...,312}
{\x\thinspace\textcom{\XeTeXglyph\x} }

\end{document}


-
To use XeTeXglyph, it says to put the "index" number afterward (e.g., \XeTeXglyph 123). Where do I find the index number? I'm using the Character viewer on Mac OS X, but all it shows are the Unicode and UTF-8 codes. –  Kevin P. Kilburn Aug 12 '13 at 10:43
You can create a font table for yourself based on the example I gave; it's also possible to enter the Unicode hex value using the \char command. E.g. \char"2665 will yield the heart character. –  Alan Munn Aug 12 '13 at 12:37

Just double click on the character in the Character Viewer (either in one of the tables, or the bigger one in the square right under "Character Info"). This will automatically try to insert it into the last window you were using.

You won't see the character (or you'll get the "strange character") if your TeXShop window is using a font that doesn't contain the Unicode character you just inserted, but the character is still there in your file. Compile it — the character should appear in the PDF.

If you want, you can go to TeXShop's preferences and change the "Document font" to your C64 font. This will only affect how you see it on your screen, not what comes out in your XeTeX output. (But, honestly, apart from checking that you inserted the right characters, do you really want to edit your entire document in that font? <shudder>)

-
Indeed! I never thought to just go ahead and compile it. I just noticed that the "strange character" it inserts is in some cases one of the characters in the different fonts listed at the bottom of the Character viewer (picture above). For some reason, it inserts the fonts from Minion Pro fonts. However, when I compile, it doesn't map to the proper glyph. I can type in any keyboard character and get the proper result. –  Kevin P. Kilburn Aug 12 '13 at 10:52
Your other problem is that you're dealing with two different fonts from the C64 package. In your Character Viewer screenshot, you're picking characters from C64 Elite, which uses one of the Private Use areas of the Unicode chart where characters mean nothing but what each font designer wants them to. Your XeTeX document is using C64 Pro, which uses standard Unicode ranges (like Box Drawing) and probably contains no characters in the Private Use range. So either use C64 Elite in your \newfontfamily declaration, or pick characters for C64 Pro's encoding (as listed on the style64.org website). –  Kevin Russell Aug 12 '13 at 12:42
I didn't realise I was picking from C64 Elite, so thanks for pointing that out. –  Kevin P. Kilburn Aug 12 '13 at 12:49