Skip to main content
Logo image

PreTeXt Sample Book: Abstract Algebra (SAMPLE ONLY)

Section 3.1 Programs

View Source for section
<section xml:id="inactive-code">
    <title>Programs</title>
    <p>
      First, some samples of programs that are not interactive.
      They will be syntax highlighted if a valid <attr>language</attr> is specified.
      Optionally, lines can be numbered and selected lines highlighted.
    </p>
    <xi:include xmlns="http://www.w3.org/2001/XInclude" href="./rune-examples/static-listing-java.xml" />
    <p>
      Instead of specifying <attr>language</attr> on each program,
      a default can be specified at <c>docinfo/programs/@language</c>.
      That value will be used for any program that lacks a <attr>language</attr> attribute.
      This sample does not specify it's own <attr>language</attr> and is relying on the default set in this book.
    </p>
<listing>
<caption>Python program, relying on default programs language</caption>
<program line-numbers="yes">
<code>
def say_hello():
print("Hello, World!")
say_hello()
</code>
</program>
</listing>
  </section>
First, some samples of programs that are not interactive. They will be syntax highlighted if a valid @language is specified. Optionally, lines can be numbered and selected lines highlighted.
Instead of specifying @language on each program, a default can be specified at docinfo/programs/@language. That value will be used for any program that lacks a @language attribute. This sample does not specify it’s own @language and is relying on the default set in this book.
View Source for listing
<listing>
<caption>Python program, relying on default programs language</caption>
<program line-numbers="yes">
<code>
def say_hello():
print("Hello, World!")
say_hello()
</code>
</program>
</listing>
View Source for program
<program line-numbers="yes">
<code>
def say_hello():
print("Hello, World!")
say_hello()
</code>
</program>
def say_hello():
print("Hello, World!")
say_hello()
Listing 3.1.1. Python program, relying on default programs language