## LaTeX: Typeset Programming Source Code & Wordwrap

I had to display JSON data on my report.

I had problem while writing it as a plain text.
– I need to make the json data distinguished from other report text.
– I also had problems with the underscores used in my json data. LaTeX will throw an error for underscores in text.

LaTeX’s Listings Package was helpful to solve this issue.

This package typesets programming codes making the source code readable. Key­words, com­ments and strings can be type­set us­ing dif­fer­ent styles (de­fault is bold for key­words, italic for com­ments and no spe­cial style for strings). Sup­port for hy­per­ref is also pro­vided.

At first, we need to use package in preamble: \usep­a­ck­age{list­ings}
Then we can provide necassary settings, like programming language to be used: \lst­set{lan­guage=Python}
Then, in the document body, we can use environment lstlist­ing for inline code.

Here is the sample LaTeX code that I used to display my JSON data:

Here is the output of the above code:

Hope this helps. Thanks.

Get New Post by Email

Find me on