1

I am trying to insert a listing in LyX in an enumeration ("\item ..."). My document is in French, with UTF8-encoding for the accents. However, when I click on the button "Program listing" in the Insert menu, LyX adds to the latex code:

\inputencoding{latin9} 
    \begin{lstlisting} 
    \end{lstlisting} 
\inputencoding{utf8}

When I try to compile, it failed if I had accents in the document after the code listing ("The control sequence marked should not appear between \csname and \endcsname.")

However, if I insert manually (Ctrl+L) just the environment lstlisting (or even just lstinline, which is my objective) without any encoding option, it compiles perfectly, but it doesn't look as some code in LyX.

What can I do? Indeed, I would like to have the nice look of the code in LyX.

Thank you.

The log: https://pastebin.com/TBvd7vqS

The minimal .lyx file: https://pastebin.com/42cBkzdx

The .tex produced: https://pastebin.com/gyDef1Uj

jd6
  • 133
  • 4
  • 1
    You might get more help if you post minimal example .lyx and .tex files. See here: https://wiki.lyx.org/FAQ/MinimalExample – scottkosty Apr 11 '20 at 22:27
  • 1
    Thanks for your comment! I edited my post to provide a minimal example. Are there other things I could do? – jd6 Apr 12 '20 at 06:49
  • 1
    Nice clean mwe, thanks. The .lyx file compiles without error for me. I get this PDF: https://www.dropbox.com/s/41gqps1uaock3vs/mwe.pdf. I have a different system though, Ubuntu with TeX Live. Hopefully someone else has an idea what's going wrong. If you don't get help here, consider joining lyx-fr@lists.lyx.org. Probably users on that list have familiarity with UTF-8 (and hopefully listings?). Or lyx-users@lists.lyx.org – scottkosty Apr 12 '20 at 12:52
  • 1
    Thank you for the answer! I will wait a few days to see if anyone has any ideas, before joining lists.lyx.org – jd6 Apr 12 '20 at 13:50
  • 1
    I found an alternative. I replaced pdflatex with luatex in the settings, and now it works with luatex. But I am still interested in finding a solution with pdf latex. – jd6 Apr 13 '20 at 12:54
  • Furthermore, the attribute "backgroundcolor" of lstlisting doesn't work (I tried to make it gray). Has someone any ideas ? Thanks. – jd6 Apr 13 '20 at 13:04
  • For the color, I also found a trick there : https://tex.stackexchange.com/questions/30845/how-to-redefine-lstinline-to-automatically-highlight-or-draw-frames-around-all/30851#30851 – jd6 Apr 13 '20 at 15:22

0 Answers0