Source File Listing
Similar to the source environment, the sourcefile command formats and highlights source code that is stored in an attached file.
\sourcefile[opts]{filename}
valid options:
page=path
lang=name
linenums=0|1
linestart=#
linestep=#
tabwidth=#
highlight='#, #, #,...'
link=type
style=classnames
- filename
-
A required argument that provides the name of the attached file to be included and formatted. By default, the file extension is used to determine the source type.
- page
-
The link path to the page containing the attached file. The default is the current page.
- link
-
The type or style of the link used to download the attachment.
Value Description fancy produces a gui tab like link at the top of the listing. text includes a text based link below the listing, similar to a figure caption. top same as @@text@@, but the caption is placed at the top. hide omit or hide the attachment link. - lang
-
The name of the language for the code contained within the block. The default is to use the extension of the file to determine the source language. If supplied, this key overrides the default value. A list of supported languages is provided on the Supported Languages page.
- 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
Value Description listing use a fancy style that mimics zebra stripes or green bar paper.
Examples
- \sourcefile{sample.cc}
- float avg;
- avg = (grade1 + grade2 + grade3) / 3.0;
- if(avg >= 90)
- printf("Excellent Work!\n");
- printf("Your average is %0.2f\n", avg);
- \sourcefile[linenum]{sample.cc}
- float avg;
- avg = (grade1 + grade2 + grade3) / 3.0;
- if(avg >= 90)
- printf("Excellent Work!\n");
- printf("Your average is %0.2f\n", avg);
Examples - Listing Styles
- \sourcefile[style=listing]{sample.cc}
- float avg;
- avg = (grade1 + grade2 + grade3) / 3.0;
- if(avg >= 90)
- printf("Excellent Work!\n");
- printf("Your average is %0.2f\n", avg);
- \sourcefile[style=listing linenums]{sample.cc}
- float avg;
- avg = (grade1 + grade2 + grade3) / 3.0;
- if(avg >= 90)
- printf("Excellent Work!\n");
- printf("Your average is %0.2f\n", avg);
Examples - Attachment Link Styles
- \sourcefile[link=text]{sample.cc}
- float avg;
- avg = (grade1 + grade2 + grade3) / 3.0;
- if(avg >= 90)
- printf("Excellent Work!\n");
- printf("Your average is %0.2f\n", avg);
- \sourcefile[link=top]{sample.cc}
- float avg;
- avg = (grade1 + grade2 + grade3) / 3.0;
- if(avg >= 90)
- printf("Excellent Work!\n");
- printf("Your average is %0.2f\n", avg);
- \sourcefile[link=fancy]{sample.cc}
- float avg;
- avg = (grade1 + grade2 + grade3) / 3.0;
- if(avg >= 90)
- printf("Excellent Work!\n");
- printf("Your average is %0.2f\n", avg);
- \sourcefile[link=hide]{sample.cc}
- float avg;
- avg = (grade1 + grade2 + grade3) / 3.0;
- if(avg >= 90)
- printf("Excellent Work!\n");
- printf("Your average is %0.2f\n", avg);