2

UPDATE

The new version of utfsym.sty released 2022/04/17 works with all engines.


Why can't we use XeLaTeX with the utfsym package? Is there any way to solve the problem? The following is a minimal working sample.

\documentclass{article}
\usepackage{utfsym}

\begin{document}
\usym{2680} Many
\end{document}

Furthermore, I know a solution to invoke some specific symbol which permits to use XeLaTeX or LulaLaTeX: if we want to invoke the symbold coded as abcd, we just need to find the abcd.tikz file in the package and copy the codes in the abcd.tikz file into the following blank.

\usepackage{tikz}
\makeatletter
\newcommand{\heart}{\mathord{%
\resizebox{!}{\fontcharht\font`M}{%

}%
}%
}%
\makeatother

For example, if we want to invoke the symbol coded as 2665, then we get the codes and output as follows.

\documentclass{article}

\usepackage{tikz}
\makeatletter
\newcommand{\heart}{\mathord{%
\resizebox{!}{\fontcharht\font`M}{%
\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
\begin{scope}[shift={(100.0,1876.0)},nonzero rule]
  \path[draw=.,fill=.,line width=1.600pt] (1460.0000,-1216.0000) ..
    controls (1460.0000,-1126.0000) and (1430.6667,-1028.3333) ..
    (1372.0000,-923.0000) .. controls (1335.3333,-857.0000) and
    (1276.0000,-772.3333) .. (1194.0000,-669.0000) .. controls
    (1082.0000,-527.6667) and (1001.0000,-417.6667) .. (951.0000,-339.0000) ..
    controls (869.0000,-211.0000) and (812.0000,-87.6667) .. (780.0000,31.0000) ..
    controls (748.0000,-87.6667) and (691.0000,-211.0000) .. (609.0000,-339.0000)
    .. controls (559.0000,-417.6667) and (478.0000,-527.6667) ..
    (366.0000,-669.0000) .. controls (284.0000,-772.3333) and (224.6667,-857.0000)
    .. (188.0000,-923.0000) .. controls (129.3333,-1028.3333) and
    (100.0000,-1126.0000) .. (100.0000,-1216.0000) .. controls
    (100.0000,-1308.0000) and (131.6667,-1384.3333) .. (195.0000,-1445.0000) ..
    controls (258.3333,-1505.6667) and (336.3333,-1536.0000) ..
    (429.0000,-1536.0000) .. controls (514.3333,-1536.0000) and
    (590.3333,-1504.3333) .. (657.0000,-1441.0000) .. controls
    (719.6667,-1381.6667) and (760.6667,-1308.6667) .. (780.0000,-1222.0000) ..
    controls (799.3333,-1308.6667) and (840.3333,-1381.6667) ..
    (903.0000,-1441.0000) .. controls (969.6667,-1504.3333) and
    (1045.6667,-1536.0000) .. (1131.0000,-1536.0000) .. controls
    (1223.6667,-1536.0000) and (1301.6667,-1505.6667) .. (1365.0000,-1445.0000) ..
    controls (1428.3333,-1384.3333) and (1460.0000,-1308.0000) ..
    (1460.0000,-1216.0000) -- cycle;
\end{scope}
\end{tikzpicture}
}%
}%
}%
\makeatother

\begin{document}
\Huge
$\heart$ Many things

\end{document}

enter image description here

But it seems a little complicated, is there any simple solution to invoke some specific symbol?

3 Answers 3

3

ufsym is a package that appears to use multiple

 \DeclareUnicodeCharacter

to map Unicode code points to characters drawn with tikz suitable for pdftex, it is not needed in xetex or luatex that can directly typeset Unicode code points using Unicode Opentype fonts.

enter image description here

\documentclass{article}

\usepackage{fontspec}
\setmainfont{DejaVu Sans}

\begin{document}

\symbol{"2680} Many ⚀ Many
\end{document}

If you want the tikz versions of these characers not real fonts evn with xetex, you can hide the inputenc \DeclareUnicodeCharacter

enter image description here

\documentclass{article}

% hide inputenc commands
\makeatletter
\def\DeclareUnicodeCharacter#1#2{}
\makeatother

\usepackage{utfsym}

\begin{document}

\usym{2680} Many 
\end{document}
4
  • But I want to invoke symbols in utfsym and I have to use XeLaTeX to compile my file.
    – M. Logic
    Apr 16, 2022 at 11:40
  • @M.Logic oh wait a minute you can probably access the tikz, give me a minute... Apr 16, 2022 at 11:50
  • I updated the statements.
    – M. Logic
    Apr 16, 2022 at 12:01
  • @M.Logic try now Apr 16, 2022 at 12:04
3

UPDATE

The new version of utfsym.sty released 2022/04/17 works with all engines.


OLD ANSWER

It would be easy to make utfsym to work with XeLaTeX or LuaLaTeX.

File xutfsym.sty

The file has been cut, but the modification of utfsym.sty is straightforward: just change the part up to the first \DeclareUnicodeCharacter with what's below and change all occurrences of \DeclareUnicodeCharacter with \xutfsym@declare.

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{xutfsym}[2022/04/16 Use TikZ to support icons from Unicode blocks ]
%% developed for use in package 'schule' 2016 by Daniel Spittank
%% this package is public domain, CC0
%% modified to work with (Xe|Lua)LaTeX (egreg)

%% - needs ut8 as input encoding
%% - TikZ paths are extracted from Symbola.ttf public domain font by George Douros,
%%   see: http://users.teilar.gr/~g1951d/
%% - supports direct use of unicode symbols
%% - supports textcolor
%% - supports fontsizes
%% - supported Blocks:
%%   - Miscellaneous Symbols and Arrows (2600-26FF)
%%   - Dingbats (2700-27BF)
%%   - Mahjong Tiles (1F000-1F02F)
%%   - Domino Tiles (1F030-1F09F)
%%   - Playing Cards (1F0A0-1F0FF)
%%   - Miscellaneous Symbols and Pictographs (1F300-1F5FF)
%%   - Emoticons / Emoji (1F600-1F64F)
%%   - Transport and Map Symbols (1F680-1F6FF)

\RequirePackage{xcolor}
\RequirePackage{tikz}
\RequirePackage{graphicx}
\RequirePackage{iftex}

%% command for symbol usage \usym{unicode number}
\newcommand{\usym}[1]{\resizebox{!}{\fontcharht\font`M}{\input{usym#1.tikz}}}

%% command for symbol usage as a picture, scaling by height
%% \usymH{unicode number}{height}
\newcommand{\usymH}[2]{\resizebox{!}{#2}{\input{usym#1.tikz}}}

%% command for symbol usage as a picture, scaling by width
%% \usymW{unicode number}{width}
\newcommand{\usymW}[2]{\resizebox{#2}{!}{\input{usym#1.tikz}}}

\iftutex
  % unicode engine
  \def\xutfsym@declare#1#2{%
    \begingroup\lccode`~="#1\lowercase{\endgroup\protected\def~}{#2}%
    \catcode"#1=\active
  }%
\else
  \let\xutfsym@declare\DeclareUnicodeCharacter
\fi

%% direct unicode support
\xutfsym@declare{1F000}{\usym{1F000}}
\xutfsym@declare{1F001}{\usym{1F001}}
% many other similar lines where the original
% file has \DeclareUnicodeCharacter
% I had to cut because of size limit in answers
% Up to the following one
\xutfsym@declare{27BF}{\usym{27BF}}

\endinput

Test

Now you can try the following input file with either pdflatex or xelatex.

\documentclass{article}
\usepackage{xutfsym}

\begin{document}

♠ 🀀

\usym{2660} \usym{1F000}

\end{document}

enter image description here

The output is exactly the same with both engines.

Comments

A possible development is to add a check whether the character is available in the current font so not to need to \input a TikZ picture.

10
  • So I think the codes of the package which has a lot of beautiful symbols should be written in this way or @David Carlisle 's way. Then it would be more convenient. Maybe you could sent the question and answers to the author of the package.
    – M. Logic
    Apr 16, 2022 at 12:53
  • 2
    @M.Logic Mail sent
    – egreg
    Apr 16, 2022 at 13:16
  • By the way, a few unicodes, for example, unicodes 2605 and 2606, in the package are also in most of the Chinese fonts, and so if we write the package in this way and also invoke such Chinese fonts, will they conflict with each other?
    – M. Logic
    Apr 16, 2022 at 14:07
  • @M.Logic No, with the check I proposed to the authors and mentioned in the final paragraph.
    – egreg
    Apr 16, 2022 at 14:24
  • I comment [...] since otherwise it will produce errors.
    – M. Logic
    Apr 16, 2022 at 14:40
0

Use the latest version, which can be found at https://gitlab.com/gi-fg-ibnw/utfsym.

1
  • Thanks for your update on the package!
    – M. Logic
    Apr 17, 2022 at 16:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .