I want to format part of a paragraph in typewriter font. Is there a shortcut to quickly switch to the typewriter font in Lyx?

Or even better: is there a concept like character styles in Lyx so that I can have all my programming code (as in Java programming code) appear in the same way? I do not want the whole paragraph to be in this style, just a part of a paragraph.

  • 14
    Ctrl + Shift + P. No time to find/write an answer for the second part. Apr 18, 2013 at 9:47
  • Welcome to TeX.sx! Apr 18, 2013 at 9:47
  • @PeterJansson: I am sorry, I cannot see how the link answers my question, or did I miss anything on that page?
    – Hbf
    Apr 18, 2013 at 10:00
  • New posts are reviewed and a greeting is sent to the new user, hence the message/page link. Apr 18, 2013 at 10:01
  • @PeterJansson:oh, okay. So thanks for the greeting (and your response) :)
    – Hbf
    Apr 18, 2013 at 10:07

3 Answers 3


A flexible way is to make your own LyX inset (easier than it sounds). Let's start with the "code" inset that is in LyX's Logical Markup module. If you don't need to customize it, just use the module by going to Document > Settings > Modules and add "Logical Markup". But you sound like you might enjoy customizing it, so let's copy it. Put the following in Document > Settings > Local Layout:

InsetLayout Flex:Code
    LyxType               charstyle
    LabelString           code
    LatexType             command
    LatexName             code
      Family              Typewriter
    InToc                 true
    HTMLTag               code

Then click "Validate". Then click OK. Your new inset "Code" is available in the Edit > Text Style menu.

For more information, see Help > Customization. Read sections 5.2 and 5.3.

To make a shortcut out of it, go to Tools > Preferences > Editing > Shortcuts. Click on "New". For the Function, put flex-insert "Code". Then choose your key binding.

  • Thanks for both mentioning the ready-made module and including the code equivalent ready for customization!
    – Joel Purra
    Mar 24, 2014 at 13:00

There is a module for logical markup in LyX v. 2.0.7

Enable it: Document > Settings > Modules and add the logical markup module.

Use it: Highlight the text you want marked up, go to Edit > Text style > Code.


may be you should have a look to the listings (texdoc listings) package, which can perform a good layout for java code.

  • 1
    In LyX, Insert --> Program listings to use listing. Apr 18, 2013 at 9:44
  • 1
    @TorbjørnT.: My question asks for changing the font/style of a text within a paragraph (at least, that was my intention, and I have altered the question accordingly).
    – Hbf
    Apr 18, 2013 at 9:56
  • @Hbf Yes, I know. You can use listings inline as well though, but you have to modify the settings for the inset, which is inconvenient. My comment was mainly intended as an "extension" of the answer to mention that listings has an interface within LyX already. Apr 18, 2013 at 10:17
  • @TorbjørnT. Makes sense, thanks for the clarification!
    – Hbf
    Apr 18, 2013 at 11:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .