First and foremost, I have found some solutions here, here, and there but they seem overly complicated for what I am trying to accomplish.


I am trying to somewhat reproduce the code environment "markdown-style" in LaTeX. I used a colorbox in conjunction with texttt to get a pretty satisfying look but it does not allow line breaks and thus breaks everything when used with paths or long lines.


It is my understanding that colorbox cannot be used to output multiple lines. What could help me achieve this while keeping the code fairly clean?


test \code{code} test \code{+}


  • 2
    Welcome to TeX.SX! Have you looked at listings or minted? Those are both packages for code highlighting and as far as I know they support background color as well as line breaking. I'd start with minted if you have no problem compiling with -shell-escape. :) Nov 22 '16 at 14:39
  • @Guilherme Z. Santos I do use minted when I need to display code blocks indeed. What I am looking for here is a way to show inline code snippets.
    – Akaizoku
    Nov 23 '16 at 10:32
  • 1
    Both minted and listings offer macros to display inline code. Minted macro is: \mintinline{<language>}{code}. Nov 23 '16 at 10:34
  • @Guilherme Z. Santos Thank you for the heads up. I think I will be working with this as for now. I will keep looking for a way to manage to do so without minted when I find some time.
    – Akaizoku
    Nov 23 '16 at 11:11
  • why would you want to do it without minted? If there's a specific reason you're looking to use the package less perhaps you should see the listings package, I think they are compatible . Not using listing packages at all will surely lead to an overcomplicated solution which you seem to want to avoid... Nov 23 '16 at 14:36

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.