☰ Click for Table of Contents
BookWiki Documentation
Copyright 2026
Rance D. Necaise

Source Code Listing

The source environment is used to format and highlight the source code for most any programming language. A number of options are provided for including line numbers highlighting specific lines and applying a variety of default styles. A number of examples are provided below the environment definition.

source module
\begin{source}[
         lang=name
         linenums=0|1 
         linestart=#
         linestep=#
         tabwidth=#
         highlight='#, #, #,...'
         style=classnames
    ....
\end{source}
This environment is used to format and hightlight any programming language in either a plain simple style or a fancy style that mimics green bar paper. A default language can be specified by setting the SourceLang configuration entry using the BwApp::set('SourceLang', 'cpp'); statement in the application configuration file. By setting the configuration entry, the lang key does not have to be specified each time.
Keys:
lang

The name of the language for the code contained within the block. A list of supported languages is provided on the Supported Languages page. If no language is provided, then the default specified by the configuration setting SourceLang is used. The default is for plain text. To display source code that is not highlighted, use the code environment instead.

linenums

Determines whether line numbers are included in the list. The default is false (0).

linestart

Indicates the first line number used when numbering the lines. This is useful a source listing is split across multiple blocks or only a portion of the code is included.

linestep

Indicates which line numbers, if any, should be boldfaced. For a value of 2, every other line number would be boldfaced. The default is for every 5th line number to be boldfaced. If set to 0, no line numbers are styled in boldface.

tabwidth

Sets the number of spaces to use for tab (\t) replacement.

highlight

A list of one or more line numbers to be highlighted. The line numbers in the list can be separated by spaces, commas, or semicolons.

style

The name of one or more css class selectors for modifying the default style of the program code block. A standard style is defined for the source code environment

ValueDescription
listinguse a fancy style that mimics zebra stripes or green bar paper.
Plugin:  SourceCode

Examples

Example
source
  1. \begin{source}[lang=cpp]
  2. float avg;
  3. avg = (grade1 + grade2 + grade3) / 3.0;
  4.  
  5. if(avg >= 90)
  6.   printf("Excellent Work!\n");
  7.  
  8. printf("Your average is %0.2f\n", avg);
  9. \end{source}
  1. float avg;
  2. avg = (grade1 + grade2 + grade3) / 3.0;
  3.  
  4. if(avg >= 90)
  5.   printf("Excellent Work!\n");
  6.  
  7. printf("Your average is %0.2f\n", avg);
results
Example
source
  1. \begin{source}[lang=cpp linenums=1]
  2. float avg;
  3. avg = (grade1 + grade2 + grade3) / 3.0;
  4.  
  5. if(avg >= 90)
  6.   printf("Excellent Work!\n");
  7.  
  8. printf("Your average is %0.2f\n", avg);
  9. \end{source}
  1. float avg;
  2. avg = (grade1 + grade2 + grade3) / 3.0;
  3.  
  4. if(avg >= 90)
  5.   printf("Excellent Work!\n");
  6.  
  7. printf("Your average is %0.2f\n", avg);
results

Examples - Listing Style

Example
source
  1. \begin{source}[lang=cpp style=listing]
  2. float avg;
  3. avg = (grade1 + grade2 + grade3) / 3.0;
  4.  
  5. if(avg >= 90)
  6.   printf("Excellent Work!\n");
  7.  
  8. printf("Your average is %0.2f\n", avg);
  9. \end{source}
  1. float avg;
  2. avg = (grade1 + grade2 + grade3) / 3.0;
  3.  
  4. if(avg >= 90)
  5.   printf("Excellent Work!\n");
  6.  
  7. printf("Your average is %0.2f\n", avg);
results
Example
source
  1. \begin{source}[lang=cpp linenums style=listing]
  2. float avg;
  3. avg = (grade1 + grade2 + grade3) / 3.0;
  4.  
  5. if(avg >= 90)
  6.   printf("Excellent Work!\n");
  7.  
  8. printf("Your average is %0.2f\n", avg);
  9. \end{source}
  1. float avg;
  2. avg = (grade1 + grade2 + grade3) / 3.0;
  3.  
  4. if(avg >= 90)
  5.   printf("Excellent Work!\n");
  6.  
  7. printf("Your average is %0.2f\n", avg);
results
  August 20, 2026 at 05:13 PM