I want to add an inline text formatted as code in Lyx. For example:

"The gradient is calculated via math::gradient(v)"

I am aware of the Insert List command, but it is not what I'm looking for since the code listing is not inserted inline. I have searched everywhere, but I can't find the way to do it.

Thanks in advance.

  • The most common options are \verb from the LaTeX base classes, \lstinline from the listings package, or \mintinline from the minted package. I suggest using the listings package because it provides some basic highlighting customization but doesn't require an external program to be run during compilation. – siracusa Nov 8 '18 at 15:42
  • Thanks @siracusa!. Actually Lyx is using the \begin{lstlisting} when using the Insert Listing option, but the listing is not inserted inline... – nodarkside Nov 8 '18 at 15:49

You can insert an inline program listing in LyX as follows:

  1. Insert > Program Listing
  2. With the cursor inside the newly created listings box, go to Edit > Listings Settings (or right click inside the box and choose "Settings").
  3. In the settings dialog, check the box "Inline listing".

Starting with LyX 2.3.0, you can optionally choose to (globally) use the minted package for listings, by going to Document > Settings > Listings and selecting "Minted" in the combo box.

| improve this answer | |

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.