0

I would like to add utf8 symbol 8962 in pdflatex. So that

My code will have \symbol{8962}

My text will show ⌂ .

I am using the compilation sequence pdflatex biber pdflatex pdflatex

Jordan
  • 87

2 Answers2

2

In PDFTeX, you need to do this on a case-by-case basis. Look for your symbol in the Comprehensive LaTeX Symbols List, or try detexify. The packages textcomp, amssymb, stix, stix2 and pifont have particularly large selections of symbols that are also in Unicode.

That particular symbol is available in both stix and stix2 as \house. Although the exact syntax you want conflicts with standard LaTeX, you can also make any arbitrary Unicode character active with newunicodechar.

\documentclass[varwidth, preview]{standalone}

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

\usepackage[notext]{stix2}
\usepackage{newunicodechar}

\newunicodechar{⌂}{\ensuremath{\house}}

\begin{document}

The ⌂ is an office building, not a house.

\end{document}

Stix Two sample

That example is going to change all your math symbols in a way you might not want, however. It is possible, through some reverse-engineering, to import only the particular symbols you want, but you might run out of LaTeX math alphabets.

To make the same document body work with Unicode, you could replace most of the preamble with \usepackage{unicode-math}, which also defines \house. This particular symbol is not present in the default text or math fonts, but you could load it from XITS, Stix Math or Stix Two Math:

\documentclass[varwidth, preview]{standalone}

\usepackage{newunicodechar}
\usepackage{unicode-math}

\setmathfont{Latin Modern Math}
\setmathfont[range={`⌂}, Scale=MatchUppercase]{Stix Two Math}
\newunicodechar{⌂}{\ensuremath{\house}}

\begin{document}

The ⌂ is an office building, not a house.

\end{document}

unicode-math sample

An alternative using only fontspec is:

\documentclass[varwidth, preview]{standalone}

\usepackage{newunicodechar}
\usepackage{fontspec}

\newfontfamily{\pifamily}{DejaVu Serif}[Scale=MatchUppercase]

\newunicodechar{⌂}{{\pifamily{}⌂}}

\begin{document}

The ⌂ is an office building, not a house.

\end{document}

fontspec sample

Since that would break as input in in math mode, you might instead declare the text-mode symbol as \texthouse.

Either of the previous two examples allow you to use either plain TeX \char or LaTeX \symbol with the Unicode code point, in LuaLaTeX or XeLaTeX. PDFLaTeX simply does not support that.

Davislor
  • 44,045
0

My best solution:

% Preamble
\newrobustcmd*{\myhome}[1][black]{\tikz{\draw (0,0) -- (0,.15cm) -- (.1cm,.25cm) -- (.2cm,.15cm) -- (0.2cm,0) -- (0,0);}}

% Text
Which is located at \myhome ~ on the map.
Jordan
  • 87