Connexions

You are here: Home » Content » The Intermediate CNXML
Content Actions

The Intermediate CNXML

Module by: Ricardo Radaelli-Sanchez

Summary: This is the second installment of the CNXML language tutorials. It is designed to give a more comprehensive look at the CNXML tags and explain some more advanced uses of the language. Includes helpful examples of CNXML tags, extending the module created in The Basic CNXML tutorial.

Example

As is often the case in textbooks, authors will include examples in the middle of a chapter or section. For this reason CNXML provides a tag that allows an author to include examples in a document. The example tag has a unique id attribute and can contain most tags as children, the first being an optional name. For specifics you should always consult the CNXML Spec.
Example 1 
	  
<example id='tboneexam'>
  <figure id='tbonefig'>
    <name>T-Bone Steak</name>
    <media type='image/jpg' src='tbone.jpg'/>
  </figure>
</example>
	  
	

Figure

The figure tag provides the structure for creating a figure within a document. They can contain either two or more subfigure tags, or a single media, table, or code tag.
The figure tag has two attributes:
  • id - a unique ID, required
  • orient - defines how multiple subfigures are to be displayed. It takes two values, vertical or horizontal, and will default to horizontal.
The optional first tag of the figure tag is name which is used to title a figure.
The name tag is followed by any of the tags listed above; however, the most commonly used tag is media, which is used to include any sort of media such as images, video, music, or java applets. The media tag has two attributes:
  • src - the location of the displayed media
  • type - defines the type of media being displayed, which can be any valid MIME type.
    • audio/FILETYPE - audio/mp3, audio/wav, etc.
    • video/FILETYPE - video/qt, video/mov, etc.
    • image/FILETYPE - image/png, image/gif, etc.
    • application/FILETYPE - application/PostScript, application/x-java-applet, etc.
The final tag is the optional caption which is used to add a small caption to the figure.
Example 2 
	  
<figure id='tbone'>
  <name>T-Bone Steak</name>
  <media type='image/jpeg' src='tbone.jpg'/>
  <caption>
    Upon successful completion of these documents, you should be able
    to grill a steak that looks just as good!
  </caption>
</figure>
	  
	

Subfigure

The subfigure tag is used when you want to include more than one media, code or table within the same figure.
The usage of the subfigure tag is similar to that of figure. It has an optional id attribute, an optional first child name tag, a single media, code or table, followed by an optional caption.
Now the orient attribute for figure becomes very important. orient lets you specify whether the subfigures should be displayed side-to-side or one on top of the other.
Example 3 
	  
<figure orient='horizontal' id='horfig'>
  <name>Steaks</name>
  <subfigure id='subfigtbone1'>
    <name>T-Bone</name>
    <media type='image/jpeg' src='tbone.jpg'/>
  </subfigure>
  <subfigure id='subfingnystrip1'>
    <name>New York Strip</name>
    <media type='image/jpeg' src='ny_strip.gif'/>
  </subfigure>
  <caption>
      Upon successful completion of these documents, you
      should be able to grill a steak that looks just as good!
  </caption>
</figure>
	  
	  
Or
	  
<figure orient='vertical' id='verfig'>
  <name>Steaks</name>
  <subfigure id='subfigtbone2'>
    <name>T-Bone</name>
    <media type='image/jpeg' src='tbone.jpg'/>
  </subfigure>
  <subfigure id='subfig2'>
    <name>New York Strip</name>
    <media type='image/jpeg' src='ny_strip.jpg'/>
  </subfigure>
  <caption>
    Upon successful completion of these documents, you
    should be able to grill a steak that looks just as good!
  </caption>
</figure>
	    
	  

List

The list tag is used to make lists. It has two attributes:
  • id - a unique ID, required
  • type - defines the formatting of the list. type takes the values bulleted (default), enumerated, named-item or inline
The list tag has two children: name, which is optional, and item, which is where the list information is stored.
Example 4: Example List 
	    
<list id='marinade' type='enumerated'>
  <name>Beer Marinade</name>
  <item>pour beer into large bowl</item>
  <item>add chili powder to taste</item>
  <item>squeeze half lime into beer marinade</item>
  <item>place steak in beer, let soak for 30 minutes</item>
</list>
	    
	  
The resulting list will look like:
    Beer Marinade
  1. pour beer into large bowl
  2. add chili powder to taste
  3. squeeze half lime into beer marinade
  4. place steak in beer, let soak for 30 minutes
Example 5: New List Types Example 

Named Item Lists

CNXML 0.5 sees the introduction of two new types of lists. The first type is known as a named item list. To use this type of list set the type attribute in the list tag to named-item. Each of the items in the named list will have a name.
	      
<list id='marinade' type='named-item'>
  <name>Beer Marinade</name>    
  <item><name>Step 1</name>pour beer into large bowl</item>
  <item><name>Step 2</name>add chili powder to taste</item>
  <item><name>Step 3</name>squeeze half lime into beer marinade</item>
  <item><name>Step 4</name>place steak in beer, let soak for 30 minutes</item>
</list>
	      
	    
The resulting list will look like:
Beer Marinade
Step 1 - pour beer into large bowl
Step 2 - add chili powder to taste
Step 3 -  squeeze half lime into beer marinade
Step 4 -  place steak in beer, let soak for 30 minutes

Inline Lists

The other new type of list is the inline list. This type is used to specify semantically that a list is present. For example:
	       
In order to make a good marinade follow these directions:<list
id='marinade' type='inline'>
  <name>Beer Marinade</name>
  <item><name>Step 1</name>pour beer into large bowl</item>
  <item><name>Step 2</name>add chili powder to taste</item>
  <item><name>Step 3</name>squeeze half lime into beer marinade</item>
  <item><name>Step 4</name>place steak in beer, let soak for 30 minutes</item>
</list>.
	      
	    
The resulting list will look like: In order to make a good marinade follow these directions: Beer Marinade: Step 1 - pour beer into large bowl; Step 2 - add chili powder to taste; Step 3 - squeeze half lime into beer marinade; Step 4 - place steak in beer, let soak for 30 minutes

Equation

The equation tag is used to set off and number equations in CNXML documents by using ASCII text and embedded media to display math.
note: It is strongly encouraged, however, to use equation with MathML tags when displaying math.

ASCII Text and Images

The first child is an optional name followed by any number of media tags embedded into ASCII text.
Example 6 
	    
<equation id="eqn14">
  <name>Euler's Relation</name>
  <media type='image/gif' src='euler.gif' />
</equation>
	    
	    
	    
<equation id='eqn15'>
  <name>Simple Arithmetic</name>
    11+27=38
</equation>
	    
	    
This equation will display as:
Simple Arithmetic 11+27=38 (1)

Definition

The definition tag is used to define a word in a CNXML document. It has a required id attribute and three children: term, meaning and example. How to use definition is a little confusing, so don't forget to check out Example 7.
The first child tag should be term which contains the word/phrase being defined. It is then followed by a meaning tag which is follwed by any number of examples. This process repeats for all meanings.
Example 7 
	  
<definition id='tbonedef'>
  <term>T-Bone</term>
  <meaning>
    "The T-bone steak is cut between 1 and 3 inches thick and comes
     from the center section of the short loin. This steak is
     characterized by its T-shape bone, has a fine-grained shell and a
     small tenderloin eye,"
     <cite>http://www.chophousecalgary.com/steak.html</cite>.
  </meaning>
  <example id='tboneexam'>
    <figure id='tbonefig'>
      <name>T-Bone Steak</name>
      <media type='image/jpeg' src='tbone.jpg'/>
    </figure>
  </example>
</definition>
	  
	
Definition 1: T-Bone
"The T-bone steak is cut between 1 and 3 inches thick and comes from the center section of the short loin. This steak is characterized by its T-shape bone, has a fine-grained shell and a small tenderloin eye," http://www.chophousecalgary.com/steak.html.
Example 
T-Bone Steak
tbone.jpg
Figure 1

Rule

The rule tag is used to insert a rule, such as a theorem, axiom, or rule of thumb, into a cnxml document. It has two attributes:
  • id - required, unique ID
  • type - required, specificies the type of rule (e.g. theorem, axiom, rule of thumb, etc.)
It may also have an optional name and it must have one or more statement tags and zero or more proof or example tags.

Statement

The statement tag is used inside a rule tag and defines the statement of the rule. It has an optional id attribute, which, like all IDs, must be unique. It also has two children, para and equation.

Proof

The proof tag is used inside the rule tag and marks the proof of the rule. It has an optional id attribute and may contain another rule, para, equation, figure, or list tag.

Using rule

Example 8 
	    
<rule id='murph' type='law'> 
  <name>Murphy's Law</name>
  <statement>
    <para id='murphp1'>
      If there are two or more ways to do something, and one of those
      ways can result in a catastrophe, then someone will do it.
    </para>
  </statement>
  <proof>
    <para id='murphp2'>
      Edward A. Murphy, Jr. was one of the engineers on the
      rocket-sled experiments that were done by the U.S. Air Force in
      1949 to test human acceleration tolerances (USAF project
      MX981). One experiment involved a set of 16 accelerometers
      mounted to different parts of the subject's body. There were two
      ways each sensor could be glued to its mount, and somebody
      methodically installed all 16 the wrong way around. Murphy then
      made the original form of his pronouncement, which the test
      subject (Major John Paul Stapp) quoted at a news conference a
      few days later
      <cite>http://www.lylemariam.com/murphy.htm</cite>.
    </para>
  </proof>
</rule>
	    
	  
law 1: Murphy's Law 
If there are two or more ways to do something, and one of those ways can result in a catastrophe, then someone will do it.
Proof
Edward A. Murphy, Jr. was one of the engineers on the rocket-sled experiments that were done by the U.S. Air Force in 1949 to test human acceleration tolerances (USAF project MX981). One experiment involved a set of 16 accelerometers mounted to different parts of the subject's body. There were two ways each sensor could be glued to its mount, and somebody methodically installed all 16 the wrong way around. Murphy then made the original form of his pronouncement, which the test subject (Major John Paul Stapp) quoted at a news conference a few days later http://www.lylemariam.com/murphy.htm.

Finishing Remarks

Thanks for making it through another tutorial. I'm sure that you still want to know more so here's my link (actually a cnxn) to The Advanced CNXML. And remember to always consult the CNXML Spec when writing documents.

Comments, questions, feedback, criticisms?

Send feedback