I want to add these two utf-8 symbols ☐ , ⌧ in my latex document, I also added \usepackage[utf8]{inputenc}
. How can I do that?
-
1Well: is your file utf8? Are you using pdflatex or xelatex? Also what do you need the symbols for? The usage might change how you can insert them.– AlenannoFeb 9, 2016 at 9:16
-
@Alenanno just have editted my question.– Lucky_girlFeb 9, 2016 at 9:24
2 Answers
If you use a Unicode engine (xetex
or luatex
) it is just a matter of finding a font, which offers these symbols. I have expereinced the DejaVu Sans font to be pretty complete in that regard. You might not want to change the font of the whole document just for these symbols, so it becomes necessary to allocate a \newfontfamily
which I named \boxedsymbols
. Then you can locally switch fonts to print the exotic symbols.
\documentclass{article}
\usepackage{fontspec}
\newfontfamily\boxedsymbols{DejaVu Sans}
\begin{document}
Here we go: {\boxedsymbols ☐ ⌧}
\end{document}
For pdflatex
, there is the possibility to make the Unicode characters active and define them to print a symbol, that is available in the font, which looks similar. Here I use the math symbols \square
and \boxtimes
(from amssymb
). Note, that these are not the actual Unicode symbols which you enter in your document, but rather visual equivalents.
If you want to use them in math-mode as well, replace $<symbol>$
by \ensuremath{<symbol>}
. (This is one of the rare cases, where \ensuremath
is appropriate.)
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}% for \boxtimes
\usepackage{newunicodechar}
\newunicodechar{☐}{$\square$}
\newunicodechar{⌧}{$\boxtimes$}
\begin{document}
Here we go: ☐ ⌧
\end{document}
The functionality obtained with the pdflatex
solution, namely typing the symbols directly without having to switch fonts, seems appealing and can also be achieved with the xetex
/luatex
variant. Bear in mind, that this is not really a good practice, as now the characters ☐
, ⌧
are active and code is executed each time they are encountered in the text.
\documentclass{article}
\usepackage{fontspec}
\usepackage{newunicodechar}
\newfontfamily\boxedsymbols{DejaVu Sans}
\newunicodechar{☐}{{\boxedsymbols\char`☐}}
\newunicodechar{⌧}{{\boxedsymbols\char`⌧}}
\begin{document}
Here we go: ☐ ⌧
\end{document}
The output is the same as for the first variant.
You can load the wasysym
package and use these commands. Note the \
being used to preserve the space after a macro.
\documentclass{article}
\usepackage{wasysym}
\begin{document}
Do you like \LaTeX? \Square\ Yes – \Square\ No
You can answer using \CheckedBox\ or \XBox, but don't leave it empty!
\end{document}
-
-
Is it just me, or does the
\CheckedBox
symbol look a bit off with respect to the placement of the check mark inside the box?– SverreFeb 9, 2016 at 13:59 -
-
I think
\CheckedBox
is the only admissible answer to the question in your example! Feb 9, 2016 at 15:14 -