10

I want to add these two utf-8 symbols ☐ , ⌧ in my latex document, I also added \usepackage[utf8]{inputenc}. How can I do that?

My input should look like this: enter image description here

2
  • 1
    Well: 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.
    – Alenanno
    Feb 9, 2016 at 9:16
  • @Alenanno just have editted my question.
    – Lucky_girl
    Feb 9, 2016 at 9:24

2 Answers 2

14

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}

enter image description here

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}

enter image description here

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.

11

You can load the wasysym package and use these commands. Note the \ being used to preserve the space after a macro.

enter image description here

\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}
5
  • Perfect, thanks! That's exactly what I need!
    – Lucky_girl
    Feb 9, 2016 at 9:32
  • 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?
    – Sverre
    Feb 9, 2016 at 13:59
  • @Sverre I think it's the screenshot.
    – Alenanno
    Feb 9, 2016 at 14:20
  • I think \CheckedBox is the only admissible answer to the question in your example! Feb 9, 2016 at 15:14
  • @HenriMenke Why? :P
    – Alenanno
    Feb 9, 2016 at 15:15

You must log in to answer this question.

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