5

I am trying to show a directory structure of a tree using the listings package like so:

├── controllers
│   ├── application_controller.rb

what I get looks like this:

    controllers
            application_controller.rb

when I use

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

the error given is:

Package inputenc Error: Unicode char \u8:\lst@FillFixed@\lst@EC not set up for use with LaTeX. [├── ]

trying with utf8x gives:

./directory_listing.txt:1: Package utf8x Error: MalformedUTF-8sequence. [├── ]

and

[U+FFFD][U+FFFD][U+FFFD]
1
controllers
[U+FFFD][U+FFFD][U+FFFD]
2
[U+FFFD][U+FFFD][U+FFFD]
a p p l i c a t i o n _ c o n t r o l l e r . rb

and

âŤIJâŤĂâŤĂ controllers
âŤĆÂăÂă âŤIJâŤĂâŤĂ application_controller.rb

If I do not include the utf8 line.

Is there a way to get it to correctly encode the emdashes, pipes and three way pipes so that they show in the output? (P.s. I need some form of [T1]fontenc or underscores are not displayed correctly elsewhere.)

  • 5
    Try the dirtree package, it is better suited in what you are trying to do. – Yiannis Lazarides Aug 30 '13 at 17:56
  • @YiannisLazarides thanks, this package looks helpful, is there a way to include this package within a listing as I have a lot of listings along with a listings contents. – Mike H-R Aug 31 '13 at 4:20
4

There is a work-around, using the pmboxdraw package and listings' escapechar command, that allows to insert Latex code in listings environments:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pmboxdraw}
\usepackage{listings}
\begin{document}
Here is my code (note that I can insert \LaTeX code between ``@''):

\begin{lstlisting}[escapechar=@]
for i in @\LaTeX@:
    print @$\sum_i$@
\end{lstlisting}

Now, let's print the characters you are interrested in:

\begin{lstlisting}[escapechar=@]
@\pmboxdrawuni{251D}\pmboxdrawuni{2501}@ controllers
@\textSFxi@  @\pmboxdrawuni{251D}\pmboxdrawuni{2501}\pmboxdrawuni{2501}@ application_controller.rb
\end{lstlisting}

\end{document}

enter image description here

There might be Lualatex or XeLaTex solutions to use unicode characters: would that be an option for you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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