19

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.

  • 12
    Ctrl + Shift + P. No time to find/write an answer for the second part. – Torbjørn T. Apr 18 '13 at 9:47
  • Welcome to TeX.sx! – Peter Jansson Apr 18 '13 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 '13 at 10:00
  • New posts are reviewed and a greeting is sent to the new user, hence the message/page link. – Peter Jansson Apr 18 '13 at 10:01
  • @PeterJansson:oh, okay. So thanks for the greeting (and your response) :) – Hbf Apr 18 '13 at 10:07
14

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
    Font
      Family              Typewriter
    EndFont
    Preamble
    \newcommand{\code}[1]{\texttt{#1}}
    EndPreamble
    InToc                 true
    HTMLTag               code
End

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 '14 at 13:00
4

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.

1

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. – Torbjørn T. Apr 18 '13 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 '13 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. – Torbjørn T. Apr 18 '13 at 10:17
  • @TorbjørnT. Makes sense, thanks for the clarification! – Hbf Apr 18 '13 at 11:44

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.