2

The problem

I'm trying to insert the output of the tree command into a Program Listing field of LyX. The text is the following:

exampleFolder/
├── 01.mp4
├── 02.avi
├── 03.mov
└── 04.mpg

If this snippet is inserted in the main text, there are no problems, and the LyX-TeX document is compiled with no fuss.

If I put it inside a Program Listing field I get the following error message:

LyX: Uncodable characters in listing inset

The following characters in one of the program listings are not representable in the current encoding and have been omitted: ├──├──├──└──.

And this is the output PDF:

output PDF


Debugging info

The LaTeX source for the toy example I made is the following:

\begin{document}

exampleFolder/
\textSFviii{}\textSFx{}\textSFx{} 01.mp4
\textSFviii{}\textSFx{}\textSFx{} 02.avi
\textSFviii{}\textSFx{}\textSFx{} 03.mov
\textSFii{}\textSFx{}\textSFx{} 04.mpg

\begin{lstlisting}
exampleFolder/
<LyX Warning: uncodable character '├'><LyX Warning: uncodable character '─'><LyX Warning: uncodable character '─'> 01.mp4
<LyX Warning: uncodable character '├'><LyX Warning: uncodable character '─'><LyX Warning: uncodable character '─'> 02.avi
<LyX Warning: uncodable character '├'><LyX Warning: uncodable character '─'><LyX Warning: uncodable character '─'> 03.mov
<LyX Warning: uncodable character '└'><LyX Warning: uncodable character '─'><LyX Warning: uncodable character '─'> 04.mpg
\end{lstlisting}

\end{document}

Related questions


Findings

I've tried to change the encoding of the document to extended UNICODE, and here we find the problem.

\inputencoding{latin9}\begin{lstlisting}[style=tree]
/home/teradeep/Work/Saliency/vid2img/Videos/exampleFolder/
<LyX Warning: uncodable character '├'><LyX Warning: uncodable character '─'><LyX Warning: uncodable character '─'> 01.mp4
<LyX Warning: uncodable character '├'><LyX Warning: uncodable character '─'><LyX Warning: uncodable character '─'> 02.avi
<LyX Warning: uncodable character '├'><LyX Warning: uncodable character '─'><LyX Warning: uncodable character '─'> 03.mov
<LyX Warning: uncodable character '└'><LyX Warning: uncodable character '─'><LyX Warning: uncodable character '─'> 04.mpg
\end{lstlisting}
\inputencoding{utf8x}

LyX encodes the lstlisting in latin9, while the rest of the document is in utf8x.

So, given that "[...] listings itself is not capable to typeset multibyte characters.", a workaround is to use \lstdefinestyle{tree} as proposed by Daniel.


Workaround

This is my solution, for now: I've inputted the code directly as text, formatted with \noindent \texttt \scriptsize and replaced the space character (which was not supported) with a \hspace{1.5em}.

\noindent \texttt{\scriptsize{}Videos}{\scriptsize \par}
\noindent \texttt{\scriptsize{}├── exampleFolder}{\scriptsize \par}
\noindent \texttt{\scriptsize{}│\hspace{1.5em}├── 01.mp4}{\scriptsize \par}
\noindent \texttt{\scriptsize{}│\hspace{1.5em}├── 02.avi}{\scriptsize \par}
\noindent \texttt{\scriptsize{}│\hspace{1.5em}├── 03.mov}{\scriptsize \par}
\noindent \texttt{\scriptsize{}│\hspace{1.5em}└── 04.mpg}{\scriptsize \par}
[...]

This is the output. I think it's pretty decent.

OK solution

3
  • From what I understand, this problem is because the listings package cannot deal with multi-byte encodings, so I don't think there is anything that LyX can do to help other than warn you of the problem. One possible solution is to use XeTeX and non-TeX fonts. I tried the FreeSans fonts. It compiles without error for me but the display is not correct. For more information, see lyx.org/trac/ticket/8439#comment:2
    – scottkosty
    Apr 29 '16 at 22:03
  • Yeah, I figured that out, after a bit of research (I've been updating the question several times, since the creating date). Well, I believe that the alternative I've suggested is a fair compromise. Alternatively, I could insert a LaTeX container in LyX, so it feels like it's a listing container. I'll answer my own question, if no one comes up alternatives. Thank you for commenting.
    – Atcold
    Apr 29 '16 at 23:50
  • Makes sense. I think you should answer your question. The workarounds you've mentioned are as good as it gets for this case, I think. Unless there's a way to get the output correct for XeTeX. I don't know why it compiled without error but did not show correctly.
    – scottkosty
    Apr 30 '16 at 1:49

Your Answer

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

Browse other questions tagged or ask your own question.