# Print box drawing characters with pdfLaTeX

I need to print some unicode characters (of box drawing family) in my document. I found this question that is very similar to mine but is valid only for XeLaTeX. There is a valid way to do this with pdfLaTeX or I have to use XeLaTeX instead?

You can use the symbols, if available on the keyboard, or the macros.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pmboxdraw}
\usepackage{newunicodechar}
\newunicodechar{└}{\textSFii}
\newunicodechar{├}{\textSFviii}
\newunicodechar{─}{\textSFx}
\begin{document}

\begin{verbatim}
├── Maildir/
└── scripts/
├── backup.sh*
└── OLD/
├── backup_cleanup.sh.old
└── backup.sh.old*
\end{verbatim}

\end{document}


• It's ok with verbatim environment but i still have the same problem with lstlisting environment. Dec 3, 2015 at 14:31
• Thank you, this works great. But can you explain why we need to type the \newunicodechar definitions? Why doesn't pmboxdraw define those characters in the first place? Feb 23, 2017 at 17:50
• The utf8 encoding doesn't know such characters. The reason why you have to define the character and its command
– user2478
Feb 23, 2017 at 19:53
• @Tobia The stuff with \newunicodechar is not needed. Package pmboxdraw already handles it automatically, see my answer. Feb 23, 2017 at 20:27

This is an extension to Herbert's answer and an answer to Tobia's comment.

Package inputenc with encoding option utf8 allows the use of UTF-8 in TeX input files with 8-bit TeX engines. As prerequisite, the Unicode characters must be known, how they are mapped to TeX code. The UTF-8 support of inputenc couples this with the font encoding. Therefore package pmboxdraw defines an artificial font encoding pmboxdraw and the related mapping file pmboxdrawenc.dfu, which is then automatically loaded. This simplifies Herbert's example to:

% arara: pdflatex
\listfiles
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pmboxdraw}

\begin{document}
\begin{verbatim}
├── Maildir/
└── scripts/
├── backup.sh*
└── OLD/
├── backup_cleanup.sh.old
└── backup.sh.old*
\end{verbatim}

\end{document}


Compiled with:

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016)


Version list of \listfiles:

 *File List*
article.cls    2014/09/29 v1.4h Standard LaTeX document class
size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
fontenc.sty
t1enc.def    2005/09/27 v1.99g Standard LaTeX file
inputenc.sty    2015/03/17 v1.2c Input encoding file
utf8.def    2016/02/28 v1.1s UTF-8 support for inputenc
t1enc.dfu    2016/02/28 v1.1s UTF-8 support for inputenc
ot1enc.dfu    2016/02/28 v1.1s UTF-8 support for inputenc
omsenc.dfu    2016/02/28 v1.1s UTF-8 support for inputenc
pmboxdraw.sty    2011/03/24 v1.1 Poor man's box drawing characters (HO)
ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
kvsetkeys.sty    2012/04/25 v1.16 Key value parser (HO)
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
etexcmds.sty    2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
kvdefinekeys.sty    2011/04/07 v1.3 Define keys (HO)
pmboxdrawenc.dfu    2011/03/24 v1.1 UTF-8 support for box drawing characters
kvoptions.sty    2011/06/30 v3.11 Key value format for package options (HO)
keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
t1cmtt.fd    2014/09/29 v2.5h Standard LaTeX font definitions
***********


# LuaTeX/XeTeX version

LuaTeX and XeTeX support Unicode characters and package inputenc is deprecated. However, pmboxdrawenc.dfu can still be used to make the supported characters active and expand to the symbols:

% arara: xelatex
% or
% arara: lualatex
\documentclass{article}
\usepackage{pmboxdraw}

\begingroup
\def\DeclareUnicodeCharacter#1{%
\begingroup
\lccode\~="#1\relax
\lowercase{\endgroup
\global\catcode~=\active
\gdef~%
}%
}%
\input{pmboxdrawenc.dfu}%
\endgroup

\begin{document}
\begin{verbatim}
├── Maildir/
└── scripts/
├── backup.sh*
└── OLD/
├── backup_cleanup.sh.old
└── backup.sh.old*
\end{verbatim}

\end{document}

• Nope. Using the system that comes in with apt-get install texlive-xetex texlive-fonts-recommended lmodern on Linux Mint 18 (Ubuntu 16.04) which seems to be version 2015.20160320-1, your example comes out without the line characters. I have to explicitly define the characters with \newunicodechar. Maybe I'm missing some other package? Or is my TeX Live too old? Feb 24, 2017 at 9:53
• @Tobia The question was to do it for pdfTeX, not XeTeX. I have updated the answer and added a version for LuaTeX/XeTeX. Feb 24, 2017 at 18:44
• I got an error because I mistakenly had the option [utf8x] for the package inputenc. Once I corrected that to \usepackage[utf8]{inputenc}, it all worked fine. . . BTW, not sure what \listfiles is supposed to do? I did not need that. (Pdf-LaTeX.) Oct 13, 2020 at 14:35
• @Henke \listfiles produces the version list shown in the answer. Oct 14, 2020 at 20:03
• Yeah, OK. That makes sense. I've never bothered about these logs and output files before. In my scratch of your example I had to poke around a bit to find it -- button Logs and output files next to Recompile, and then Other logs & files > log file in the upper right. The version at overleaf seems to be relatively recent: pmboxdraw.sty 2019/12/05 v1.4 Poor man's box drawing characters (HO). BTW, your answer (without newunicodechar) is better than the accepted one, and deserves to be upvoted. :-) Oct 15, 2020 at 7:15