Skip to main content
\(\require{cancel}\newcommand{\definiteintegral}[4]{\int_{#1}^{#2}\,#3\,d#4} \newcommand{\myequation}[2]{#1\amp =#2} \newcommand{\indefiniteintegral}[2]{\int#1\,d#2} \newcommand{\testingescapedpercent}{ \% } \newcommand{\lt}{<} \newcommand{\gt}{>} \newcommand{\amp}{&} \)

Section19Pre-Formatted Text

In Sage, if you wanted to build a matrix, then you would use the matrix() constructor. Here is the matrix of second partials of \(f(x,y)=x^3+8x^2y^3 + y^4\text{,}\) as you would enter it in Sage. Notice that SR is the ring of symbolic expressions, Symbolic Ring.

var('x', 'y')
J = matrix(SR, [
    [6*x + 16*y^3, 48*x*y^2],
    [48*x*y^2, 48*x^2*y + 12*y^2]
    ])

That accomplished, Sage will easily and naturally provide a representation of the matrix with the command latex(J).

\left(\begin{array}{rr}
16 \, y^{3} + 6 \, x & -48 \, x y^{2} \\
48 \, x y^{2} & 48 \, x^{2} y + 12 \, y^{2}
\end{array}\right)

The realization of preformatted text should be robust enough that it can be cut from documents and pasted without any substitutions of “fancier” Unicode characters for generic ASCII characters. Try the “minus” sign on the \(48\) above to see if it does not become a dash, or the single quotes on the Sage variables.

For Sage input code, the first non-whitespace character sets the left margin, since legitimate Python code has no subsequent lines outdented. For pre-formatted code, the line with the least whitespace leading the line will determine the left margin. If preserving indentation is important, do not mix spaces and tabs. For syntax highlighting of text representing computer programs, or parts of them, see Section 20. Examine the source of the following example to help understand this paragraph.

        A normal line
                An indented line
An outdented line

The <c> element, for inline code snippets (or anything else in a monospace font) uses the question-mark character to tell where the text begins and ends. This will be a problem if the text has a question mark in it! So there is the attribute latexsep that allows you to specify another character that does not appear in your text. For example, XML directives use question-marks now and then, so writing about them in PreTeXt requires specifying a different separation character, as in: <?xml version="1.0" encoding="UTF-8" ?>. The <pre> element does not suffer from this quirk.

Snippets should also be robust for cut/paste operations. For example, you should not get “curly” “smart” quote marks in verbatim text: this should have "dumb" quote marks. Here are a few characters that should migrate through to a PDF unmolested: '"----"'

If you write a very long snippet of inline code it can impinge on the right margin, especially if it were to begin close to that margin. For output in LaTeX we allow line-breaking, but we do not get hyphenation and the font is fixed-width. So not always perfect. Consider a display (program listing as above with the pre element) or maybe reorganizing a sentence. And it looks like a space after that left parenthesis just got ignored in the PDF created from the latex output.

An intermediate type of verbatim text can be accomplished with the <cd> tag, short for “code display.” It allows for larger chunks of verbatim text to show up in the middle of a paragraph, but with some vertical space above and below. It can be

authored as a single line

or if you wish to have multiple lines

there is the cline tag
meant to model the line tag
and short for "code line"

and you may even

use a single cline

if you like to have your source closely model the visual look of the output.

The <pre> tag is meant for use outside of paragraphs, but is otherwise very similar. The source may also be structured as a sequence of <cline> as in the next example, recycling content from above.

If you write a very long snippet of inline 
code it can impinge on the right margin,
especially if it were to begin close to that
margin.  For output in LaTeX we allow line-breaking,
but we do not get hyphenation and the font is
fixed-width.  So not always perfect.  Consider a
display (program listing as above with the pre element)
or maybe reorganizing a sentence.