<code> Code Text

A container element for technical content such as programming language code, pseudo-code, schemas and DTDs, or a markup fragment.

Usage/Remarks

The <code> element may contain preformatted text, which may contain emphasis elements for syntax coloring, or it may contain an external link to a binary executable file.

Best Attribute Practice

The various semantic attributes should be used to name the type of code, the language, the intended platform(s), etc. Executable code should always be marked as such using the @executable attribute. The @specific-use attribute may also be used to describe the rationale or uses for a code sample.
Alternatives
When code is present in more than one form, the <code> element can be used inside an <alternatives> element. The various versions of the code can be syntax colored using the face markup from this Tag Set, syntax colored using processing instructions or other mechanisms from a syntax coloring program, plain ASCII for cut and paste, an executable version, etc.
MathML
The MathML elements to describe equations are not permitted within <code>. If equations are encountered within computer code, they can be tagged using the element <named-content> to preserve the fact that they were equations or the element <styled-content> to preserve the fact that they were set in a math font.
Related Elements
Compare to <preformat>: This element is similar to <preformat> in the preservation of whitespace, line-endings, and such formatting. The <code> element differs from <preformat> semantically; a <preformat> element may contain almost anything, for example, ASCII art, a man-machine dialog, error messages, 3 words on a line with space between them, or a poem. The <code> element is specifically for technical coding fragments, for example: computer programming language code; executable binary code; illustrative pseudo-code; an XSD, RNG, or DTD schema fragment; an SQL or XQuery query; or a markup fragment that is part of an XML document instance.
Inline versus Block: The element <code> is used for block-level code fragments. The element <monospace> is only for monospaced words or phrases that are inline with other text, for example, very short computer code snippets, parameters and operators, etc.
Attributes

Base Attributes

Miscellaneous non-JATS-specific Attributes

xml:space (fixed value = preserve)
Models and Context
May be contained in
Description
Content Model
<!ELEMENT  code         (#PCDATA %code-elements;)*                   >
Expanded Content Model

(#PCDATA | alt-text | long-desc | email | ext-link | uri | citation-alternatives | element-citation | mixed-citation | std | attrib | permissions | bold | fixed-case | italic | monospace | num | overline | roman | sans-serif | sc | strike | underline | ruby | inline-graphic | private-char | abbrev | index-term | index-term-range-end | milestone-end | milestone-start | named-content | styled-content | fn | target | tbx:entailedTerm | xref | sub | sup)*

Tagged Samples
Binary code
...
<p>... If code position 01 is assigned to &ldquo;a&rdquo;, 
 code position 02 assigned to &ldquo;A&rdquo;, code position 
 03 to &ldquo;b&rdquo;, code position 04 to &ldquo;B&rdquo; 
 and so on, a list sorted directly according to these 
 rearranged values will yield the following:
 <code>
       Sorted  Internal
       List    Values
       
       aaaa    01010101
       abbb    01030303
       Aaaa    02010101
       Abbb    02030303
 </code>
</p>
...
Coding for line types
...
<p>Define the line types:</p>
<code>
     simple_line =     (symbol_definition | collating_element | 
                        weight_assignment | order_end)? line_completion ;
     table_line =      simple_line | tailoring_line ;
     tailoring_line =  (reorder_after | order_start | reorder_end | 
                        section_definition | reorder_section_after) 
                        line_completion ;
</code>
...