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?
2 Answers
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}
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}
- 271,626
-
Nope. Using the system that comes in with
apt-get install texlive-xetex texlive-fonts-recommended lmodernon 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? – Tobia Feb 24 '17 at 09:53 -
@Tobia The question was to do it for pdfTeX, not XeTeX. I have updated the answer and added a version for LuaTeX/XeTeX. – Heiko Oberdiek Feb 24 '17 at 18:44
-
I got an error because I mistakenly had the option
[utf8x]for the packageinputenc. Once I corrected that to\usepackage[utf8]{inputenc}, it all worked fine. . . BTW, not sure what\listfilesis supposed to do? I did not need that. (Pdf-LaTeX.) – Henke - Нава́льный П с м Oct 13 '20 at 14:35 -
@Henke
\listfilesproduces the version list shown in the answer. – Heiko Oberdiek Oct 14 '20 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 filesnext toRecompile, and thenOther logs & files > log filein 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 (withoutnewunicodechar) is better than the accepted one, and deserves to be upvoted. :-) – Henke - Нава́льный П с м Oct 15 '20 at 07:15


\newunicodechardefinitions? Why doesn'tpmboxdrawdefine those characters in the first place? – Tobia Feb 23 '17 at 17:50utf8encoding doesn't know such characters. The reason why you have to define the character and its command – Feb 23 '17 at 19:53\newunicodecharis not needed. Packagepmboxdrawalready handles it automatically, see my answer. – Heiko Oberdiek Feb 23 '17 at 20:27