Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 517963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:53:18+00:00 2026-05-13T07:53:18+00:00

I need to highlight source code in LaTeX. The package listings seems to be

  • 0

I need to highlight source code in LaTeX. The package listings seems to be the best choice for most use-cases and for me it was, until now.

However, now I need more flexibility. Generally, what I’m looking for is a real lexer. In particular, I need (for an own language definition) to define (and highlight!) own number styles. listings does not allow highlighting numbers in code. However, I need to produce something like this:

Required result

listings also cannot cope with arbitrary delimiters for strings. Consider the following valid Ruby code:

s = %q!this is a string.!

Here, ! can be replaced by almost any delimiter.

(That listings cannot handle Unicode is also quite vexing, but that’s another issue.)

Ideally, I am looking for an extension of listings that allows me to provide more complex lexing rules. But barring that, I am also searching for viable alternatives.

Other threads have suggested using Pygments which can produce LaTeX output. There’s even a package – texments – to ease the transition.

However, this sorely lacks features. In particular, I am interested in listings-style line numbering, source code line references, and the possibility of embedding LaTeX in source code (options texcl and mathescape in listings).

As an example, here’s a source code typeset with listings which shows some of the things that a replacement should also provide:

LaTeX listings example: Sideways addition
[“Sideways addition” modified from Bit Twiddling Hacks]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:53:19+00:00Added an answer on May 13, 2026 at 7:53 am

    Taking Norman’s advice to heart, I’ve hacked together a solution that used (a patched) Pygments for highlighting and pushed in as many features as possible without bursting 😉

    I’ve also created a LateX package, once my Pygments patch was released in version 1.2 …

    Presenting minted

    minted is a package that uses Pygments to provide top-notch syntax highlighting in LaTeX. For example, it allows the following output.

    fancy LaTeX example

    Here’s a minimal file to reproduce the above code (notice that including Unicode characters might require XeTeX)!

    \documentclass[a4paper]{article}
    \usepackage{fontspec}
    \usepackage{minted}
    
    \setsansfont{Calibri}
    \setmonofont{Consolas}
    
    \begin{document}
    \renewcommand{\theFancyVerbLine}{
      \sffamily\textcolor[rgb]{0.5,0.5,0.5}{\scriptsize\arabic{FancyVerbLine}}}
    
    \begin{minted}[mathescape,
                   linenos,
                   numbersep=5pt,
                   gobble=2,
                   frame=lines,
                   framesep=2mm]{csharp}
      string title = "This is a Unicode π in the sky"
      /*
      Defined as $\pi=\lim_{n\to\infty}\frac{P_n}{d}$ where $P$ is the perimeter
      of an $n$-sided regular polygon circumscribing a
      circle of diameter $d$.
      */
      const double pi = 3.1415926535
    \end{minted}
    \end{document}
    

    This can be typeset using the following command:

    xelatex -shell-escape test.tex
    

    (But minted also works with latex and pdflatex …)

    minted.sty works similar to texments.sty but allows additional features.

    How to get it

    • minted is listed on CTAN (package info)

    • documentation is of course included.

    • minted is now maintained by Geoffrey Poore. The development version, including the latest .sty file, is available at github.com/gpoore/minted, and can be cloned from there.

    Once again, thanks to Norman for motivating me to produce this package.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to highlight active link in the menu. My menu is in the
Short: I need a right-click event to highlight the cell row. I am using
I need to use a custom view into a NSMenuItem. I've created a new
I want to highlight a selection of text on a web page. I have
Important: we really need the stated functionality, so please don't start suggesting alternatives. We're
Im working on a Rails based application where I have the need to allow
I'm using following method to highlight the keywords in a given text. private string
Say, I have a script nicely formatted in SSMS and it's annotated with all
A requirement for a current project of mine involves highlighting an HTML element in
I have a problem with a site I am redesigning and the problem is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.