latex source code formatting


/ Published in: LaTeX
Save to your folder(s)



Copy this code and paste it in your HTML
  1. \title{Nice Code}
  2. \author{Jonathan Bunde-Pedersen}
  3.  
  4. \documentclass[12pt]{article}
  5.  
  6. \usepackage{color}
  7. \usepackage{fancyvrb}
  8. \usepackage{listings}
  9.  
  10. % include the lines below to use a nicer fixed-width font than the default one
  11. \usepackage{fontspec}
  12. \setmonofont[Scale=0.8]{Consolas}
  13.  
  14. \lstset{fancyvrb=true}
  15. \lstset{
  16. basicstyle=\small\tt,
  17. keywordstyle=\color{blue},
  18. identifierstyle=,
  19. commentstyle=\color{green},
  20. stringstyle=\color{red},
  21. showstringspaces=false,
  22. tabsize=3,
  23. numbers=left,
  24. captionpos=b,
  25. numberstyle=\tiny
  26. %stepnumber=4
  27. }
  28.  
  29. \begin{document}
  30.  
  31. \section{Some nice Java code}
  32.  
  33. \begin{figure}[h]
  34. \lstset{language=java,caption=Nicely formatted code.,label=lst:nicecode}
  35. \begin{lstlisting}
  36. public class Whatever {
  37. public static void main(String[] args) {
  38. // whatever
  39. System.out.println("Hello, world!");
  40. }
  41. }
  42. \end{lstlisting}
  43. \end{figure}
  44.  
  45.  
  46. \end{document}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.