4

I need to use symbols \varheartsuit and \vardiamondsuit in package fdsymbol without changing other fonts, so I can't using command \usepackage{fdsymbol}.

This answer suggest using \DeclareSymbolFont and \DeclareMathSymbol, but simple replacement doesn't work here.

So how can I do a similar job?

Thanks for your time and effort.

Andrews
  • 189

2 Answers2

7

This is a short working example:

\documentclass{article}
\DeclareFontFamily{U}{FdSymbolA}{}
\DeclareFontShape{U}{FdSymbolA}{m}{n}{<->FdSymbolA-Book}{}
\DeclareSymbolFont{extrasymbols}{U}{FdSymbolA}{m}{n}
\DeclareMathSymbol{\vardiamondsuit}{\mathord}{extrasymbols}{182}
\DeclareMathSymbol{\varheartsuit}{\mathord}{extrasymbols}{184}
\begin{document}
$\vardiamondsuit\varheartsuit$
\end{document}

Explanation:

\vardiamondsuit is defined as the 182nd character in FdSymbolA-Book.pfb.

\varheartsuit is defined as the 184th character in FdSymbolA-Book.pfb.

Result:

enter image description here

domperor
  • 448
  • Thanks for your answer. And could you please explain why we need \DeclareFontFamily and \DeclareFontShape commands compared to the answer in the link? Besides, how do I know the number of a character in a package quickly? – Andrews Jul 29 '20 at 15:04
  • 1
    In fdsymbol.sty you will find \DeclareFontFamily{U}{FdSymbolA}{} \DeclareFontShape{U}{FdSymbolA}{m}{n}{ <-7.1> s * [\fdsy@scale] FdSymbolA-\fdsy@mweight@small <7.1-> s * [\fdsy@scale] FdSymbolA-\fdsy@mweight@normal }{}. I have simplified this. – domperor Jul 29 '20 at 16:16
  • 1

    Besides, how do I know the number of a character in a package quickly? I opened the FdSymbolA-Book.pfb with fontforge.app to find the char codes.

    – domperor Jul 29 '20 at 16:18
2

To add to @domperor's answer, for symbols in text mode, the \usefont command can be used.

usefont

MWE

\documentclass{article}
\DeclareFontFamily{U}{FdSymbolA}{}
\DeclareFontShape{U}{FdSymbolA}{m}{n}{<->FdSymbolA-Book}{}
\newcommand\vardiamondsuit{{\usefont{U}{FdSymbolA}{m}{n}\char182}}
\newcommand\varheartsuit{{\usefont{U}{FdSymbolA}{m}{n}\char184}}
\begin{document}
x\vardiamondsuit\varheartsuit x
\end{document}

Addendum:

There are various packages, like fonttable, for displaying the contents of a font.

Or you can just loop through the <=256 \chars of a legacy font (note: some Unicode fonts have thousands of glyphs):

some glyphs

MWE

\documentclass[12pt]{article}
\usepackage{xcolor}
%\usepackage{fdsymbol}
\DeclareFontFamily{U}{FdSymbolA}{}
\DeclareFontShape{U}{FdSymbolA}{m}{n}{<->FdSymbolA-Book}{}

%=============== font table labels \newcommand\ftlabel[1]{{\usefont{OT1}{lmr}{m}{n}\scriptsize #1}}

%------------------- font table \newcommand\displayglyphs{% \count255 = 0 \loop
\iffontchar\font\number\count255{%* \ftlabel{[\number\count255 =}\colorbox{yellow!30}{\textcolor{red!70!blue!80}{{\large\char\number\count255}}}\ftlabel{] } %need space for line-breaking }\fi \ifnum\count255 < 256 \advance\count255 by 1 \repeat }

%===================================== \begin{document} \usefont{U}{FdSymbolA}{m}{n} \displayglyphs \end{document}

Cicada
  • 10,129