Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to include the output of the npm list command in a latex verbatim block:

jeroen@jeroen-ubuntu:~/Desktop$ npm install d3
jeroen@jeroen-ubuntu:~/Desktop$ npm list
/home/jeroen/Desktop
└─┬ d3@2.10.3
  ├─┬ jsdom@0.2.14
  │ ├─┬ contextify@0.1.3
  │ │ └── bindings@1.0.0
  │ ├── cssom@0.2.5
  │ ├── htmlparser@1.7.6
  │ └─┬ request@2.12.0
  │   ├─┬ form-data@0.0.3
  │   │ ├── async@0.1.9
  │   │ └─┬ combined-stream@0.0.3
  │   │   └── delayed-stream@0.0.5
  │   └── mime@1.2.7
  └── sizzle@1.1.0

However the funny little tree characters are non ascii. I tried saving the file as UTF8 and adding \usepackage[utf8]{inputenc} to my premable. However, it gives me the errors:

 -Package inputenc Error: Unicode char \u8:â not set up for use with LaTeX

Is there any way I can use these characters?

share|improve this question
1  
1  
If you're dead set on including the actual raw text, you could compile with LuaTeX or XeLaTeX using a font that contains the relevant characters as the monospaced font. –  Alan Munn Dec 15 '12 at 3:32
    
If you don't want to use a unicode TeX, you more or less need to design an input encoding for the respective code page which can be setup to be used with the utf8 package. It's not that hard, but you need to decide whether it's worth the trouble. –  Stephan Lehmke Dec 15 '12 at 5:30
    
You can do \DeclareUnicodeCharacter{252C}{...} with ... any valid LaTeX code that draws ┬ (with picture mode or getting the glyph from a font), and the same for the other needed glyphs. –  egreg Dec 15 '12 at 11:43

2 Answers 2

up vote 6 down vote accepted

For example, package pmboxdraw provides the symbols:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pmboxdraw}

\begin{document}
\begin{verbatim}
/home/jeroen/Desktop
└─┬ d3@2.10.3
  ├─┬ jsdom@0.2.14
  │ ├─┬ contextify@0.1.3
  │ │ └── bindings@1.0.0
  │ ├── cssom@0.2.5
  │ ├── htmlparser@1.7.6
  │ └─┬ request@2.12.0
  │   ├─┬ form-data@0.0.3
  │   │ ├── async@0.1.9
  │   │ └─┬ combined-stream@0.0.3
  │   │   └── delayed-stream@0.0.5
  │   └── mime@1.2.7
  └── sizzle@1.1.0
\end{verbatim}
\end{document}

Result

share|improve this answer
    
Perfect. Is there a way of finding out which packages contain certain characters? –  Jeroen Dec 24 '12 at 3:04
    
The Comprehensive LaTeX Symbol List can help. –  Heiko Oberdiek Dec 24 '12 at 8:28

Here is a plain LaTeX solution (not using tikz). You need to set up the missing unicode chars.

Sample output

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{newunicodechar}
\makeatletter
\verbatim@font
\newsavebox\v@sp
\sbox{\v@sp}{\ }
\newlength{\v@spwd}
\setlength{\v@spwd}{\wd\v@sp}
\newunicodechar{└}{\mbox{\kern0.5\v@spwd\vrule height 2ex depth -1ex width 0.2ex\kern-0.2ex\rule[1ex]{0.5\v@spwd}{0.2ex}}}
\newunicodechar{─}{\rule[1ex]{1\v@spwd}{0.2ex}}
\newunicodechar{┬}{\rule[1ex]{0.5\v@spwd}{0.2ex}\vrule height 1ex
depth 0.5ex width0.2ex\kern-0.2ex\rule[1ex]{0.5\v@spwd}{0.2ex}}
\newunicodechar{├}{\mbox{\kern0.5\v@spwd\vrule height 2ex depth 0.5ex width 0.2ex\kern-0.2ex\rule[1ex]{0.5\v@spwd}{0.2ex}}}
\newunicodechar{│}{\mbox{\kern0.5\v@spwd\vrule height 2ex depth 0.5ex width
0.2ex\kern-0.2ex \kern0.5\v@spwd}}
\makeatother
\normalfont

\begin{document}
\begin{verbatim}
jeroen@jeroen-ubuntu:~/Desktop$ npm install d3
jeroen@jeroen-ubuntu:~/Desktop$ npm list
/home/jeroen/Desktop
└─┬ d3@2.10.3
  ├─┬ jsdom@0.2.14
  │ ├─┬ contextify@0.1.3
  │ │ └── bindings@1.0.0
  │ ├── cssom@0.2.5
  │ ├── htmlparser@1.7.6
  │ └─┬ request@2.12.0
  │   ├─┬ form-data@0.0.3
  │   │ ├── async@0.1.9
  │   │ └─┬ combined-stream@0.0.3
  │   │   └── delayed-stream@0.0.5
  │   └── mime@1.2.7
  └── sizzle@1.1.0
\end{verbatim}
\end{document}

The newunicodechar package gives a simple way to access the necessary code points.

In the code all symbols are made with vertical and horizontal rules. We need to get the width of a space character in the verbatim font and make our symbols that width to get the correct alignment in the output. The width is stored in \v@spwd and used for subsequent horizontal measurements. (I kill the width of the vertial rules by backing up by their width, to make this easier.) Also symbols starting with some space are enclosed in an box, to prevent this space disappearing at the beginning of each line.

One could adjust the height/depth of the veritcal rules to make them join up between lines, but it is probably not the style you want to see.

share|improve this answer
    
+1 (and not only for the use of newunicodechar). :) –  egreg Dec 15 '12 at 13:17
    
+1 you could replace \mbox by \mbox{}\smash which then makes it easier to enlarge the vertical rules without upsetting the interline spacings. –  jfbu Dec 15 '12 at 15:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.