Skip to main content
Logo image

Section 22 Pre-Formatted Text

View Source
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 pre element surrounds text that should be preserved verbatim. It is like a special kind of paragraph, and can be used almost everywhere that a paragraph can be used. 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 23. Examine the source of the following example to help understand this paragraph.
A normal line
An indented line
An outdented line
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 (i.e. within a <c> element) it can impinge on the right margin, since very long words will not hypenate, unless you have a dash/hypen. Such as when you use words like pneumonoultramicroscopicsilicovolcanoconiosis, parastratiosphecomyia stratiosphecomyioides, floccinaucinihilipilification, or subdermatoglyphic. For output in LaTeX we get line-breaking, and perhaps word-spacing, but we do not get hyphenation and the font is fixed-width. So not always perfect. Consider other options like <cd> or <pre> below.
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, and centered between the margins. 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.
With the @showspaces attribute of <cd> set to all there will be a visual indication of every space character, which is nice if indentation is critical. For example,
there␣is␣the␣<cline>␣tag
meant␣to␣model␣the␣line␣tag
and␣short␣for␣"code␣line"
and as single line
authored␣as␣a␣single␣line
that is not structured with <cline> elements.
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 (i.e. within
a <c> element) it can impinge on the right margin, since
very long words will not hypenate, unless you have a dash/hypen.
Such as when you use words like
pneumonoultramicroscopicsilicovolcanoconiosis,
parastratiosphecomyia stratiosphecomyioides,
floccinaucinihilipilification, or subdermatoglyphic. For output
in LaTeX we get line-breaking, and perhaps word-spacing, but we
do not get hyphenation and the font is fixed-width. So not always
perfect. Consider other options like <cd> or <pre> below.
We use a Unicode right arrow (Unicode Character ’RIGHTWARDS ARROW’, U+2192) to sometimes indicate the truncation of long lines in a text file. It is available in our usual monospace font for /PDF, but we include a use here in order to make certain that is always the case. Here: .