<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_plain.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="m9004">
  <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Using Emacs with PSGML to edit CNXML</name>

  <metadata xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
  <md:version xmlns:bib="http://bibtexml.sf.net/">2.22</md:version>
  <md:created xmlns:bib="http://bibtexml.sf.net/">2000/03/07</md:created>
  <md:revised xmlns:bib="http://bibtexml.sf.net/">2005/01/06 10:57:00.184 US/Central</md:revised>
  <md:authorlist xmlns:bib="http://bibtexml.sf.net/">
      <md:author xmlns:bib="http://bibtexml.sf.net/" id="brentmh">
      <md:firstname xmlns:bib="http://bibtexml.sf.net/">Brent</md:firstname>
      <md:othername xmlns:bib="http://bibtexml.sf.net/">Michael</md:othername>
      <md:surname xmlns:bib="http://bibtexml.sf.net/">Hendricks</md:surname>
      <md:email xmlns:bib="http://bibtexml.sf.net/">brentmh@rice.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist xmlns:bib="http://bibtexml.sf.net/">
    <md:maintainer xmlns:bib="http://bibtexml.sf.net/" id="yasushi">
      <md:firstname xmlns:bib="http://bibtexml.sf.net/">Yasushi</md:firstname>
      
      <md:surname xmlns:bib="http://bibtexml.sf.net/">Yamazaki</md:surname>
      <md:email xmlns:bib="http://bibtexml.sf.net/">yasushi@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer xmlns:bib="http://bibtexml.sf.net/" id="brentmh">
      <md:firstname xmlns:bib="http://bibtexml.sf.net/">Brent</md:firstname>
      <md:othername xmlns:bib="http://bibtexml.sf.net/">Michael</md:othername>
      <md:surname xmlns:bib="http://bibtexml.sf.net/">Hendricks</md:surname>
      <md:email xmlns:bib="http://bibtexml.sf.net/">brentmh@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist xmlns:bib="http://bibtexml.sf.net/">
    <md:keyword xmlns:bib="http://bibtexml.sf.net/">CNXML</md:keyword>
    <md:keyword xmlns:bib="http://bibtexml.sf.net/">Emacs</md:keyword>
    <md:keyword xmlns:bib="http://bibtexml.sf.net/">iso-accents-mode</md:keyword>
    <md:keyword xmlns:bib="http://bibtexml.sf.net/">PSGML</md:keyword>
    <md:keyword xmlns:bib="http://bibtexml.sf.net/">tables</md:keyword>
  </md:keywordlist>

  <md:abstract xmlns:bib="http://bibtexml.sf.net/">This module explains how to use Emacs's XML editing mode (provided by PSGML) to easily edit CNXML documents</md:abstract>
</metadata>

  <content xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
    <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="par1">
      Emacs is an extremely versatile editing environment.  In
      particular, it can use customized "modes" in which new commands
      are available.  PSGML is an emacs mode for editing SGML and XML
      documents.  It can speed up the process of marking up a document
      considerably.  Using emacs and PSGML to edit CNXML documents
      requires the following setup steps:
      
      <list xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="steps" type="enumerated">
	<item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
	  <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" target="install-emacs">Installing Emacs</cnxn>
	</item>
	<item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
	  <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" target="install">Installing PSGML</cnxn>
	</item>
	<item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
	  <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" target="catalog">Setting up an SGML catalog</cnxn>
	</item>
	<item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
	  <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" target="environ">Setting up your environment</cnxn>
	</item>
	<item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
	  <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" target="editing">Editing your document</cnxn>
	</item>
      </list>
    </para>

    <section xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="install-emacs">
      <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Installing Emacs</name>
      
      <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="inst_em1">
	Most Unix systems come with emacs already installed.  Most
	Microsoft Windows systems do not.  A precompiled version for
	Windows is available from the <link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" src="ftp://ftp.gnu.org/gnu">Gnu</link> ftp site <link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" src="ftp://ftp.gnu.org/gnu/windows/emacs/20.7/emacs-20.7-fullbin-i386.tar.gz">here</link>.
	(If you are on a Unix system that does not have emacs installed
	you will have to compile it yourself, sorry!)  Extract the
	files using a program such as <link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" src="http://www.winzip.com">WinZip</link> and install them
	somewhere.  A good place on Windows would be
	<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">C:\Program Files</code>.
      </para>
    </section>

    <section xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="install">
      <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Installing PSGML</name>
      
      <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="inst_p1">
	The next step is to ensure that you have PSGML installed on
	your system.  PSGML is a special SGML/XML editing mode for
	Emacs, written by Lennart Staflin.  Again, many Unix systems
	have it installed already, but if yours does not, it is
	available <link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" src="http://sourceforge.net/project/showfiles.php?group_id=9156">online</link>.
	If you installed your own emacs, extract the PSGML files in
	the <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">site-lisp</code> directory under your emacs
	installation.
	  
	<note xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
	  If you are on a Unix system and do not have permission to
	  modify the emacs installation, create an
	  <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">emacs</code> directory in your home directory,
	  extract the PSGML files there, and add the line
	  <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">(setq load-path (cons "~/emacs"
	  load-path))</code> to the .emacs file in your home
	  directory.
	</note>
      </para>
    </section>
    
    <section xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="catalog">
      <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Setting up an SGML catalog</name>
      
      <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="cat_p1">
	Once you have PSGML installed, you need to setup an SGML
	catalog.  This catalog provide the translation from public
	document types to physical file locations and allows emacs to
	use the tags from your specific language.  For simplicity,
	Connexions has made available a catalog containing the CNXML,
	MathML, and QML DTDs.  You can download this from our <link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" src="http://mountainbunker.org/download/sgml.zip">website</link>.
	Just download this file and extract it somewhere on you
	computer.  A good place on Unix might be
	<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">/usr/local/share</code>, or your home-directory.
	On Windows you can extract it to <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">C:\</code>.
	Remember where you extracted the files, because you will need
	this information in the next step.
      </para>
    </section>
    
    <section xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="environ">
      <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Setting up your environment</name>
      
      <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="env_p1">
	Now that everything is installed, you must configure emacs.
	The first step is to tell emacs where your SGML catalog is.
	This is most easily done by setting the environment variable
	<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">SGML_CATALOG_FILES</code> to the location of
	your catalog.  For example, if you extracted the catalog in
	the directory <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">/usr/local/share</code>, you would
	set <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">SGML_CATALOG_FILES</code> to
	<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">/usr/local/share/sgml/catalog</code>.  On Unix
	this is done in your shell initialization file
	(<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">.cshrc</code> for C-shell users and
	<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">.profile</code> for Bourne shell users).  On
	Win9X, setting variables can be done in your
	<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">C:\AUTOEXEC.BAT</code> file.  On WinNT, Win2K,
	and WinXP this is done from the System item in the control panel.
    </para>
    
    <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="env_p2">
	You also need to add some instructions to your emacs
	initialization file.  Download the
	<link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" src="xml.emacs"><code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">xml.emacs</code></link> file
	and append it to your emacs init file.  On Unix, the emacs
	init file is named <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">.emacs</code> and resides in
	your home directory.  On Windows, it is named _emacs and does
	not have a default location.
	<note xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
	  On Windows, you must set the environment variable
	  <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">HOME</code> to tell the system where your
	  _emacs file is located.  
	</note> 
	If you don't have an emacs init file already, just rename
	<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">xml.emacs</code> to <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">.emacs</code>
	or <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">_emacs</code> as appropriate.
      </para>
    </section>
    
    <section xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="editing">
      <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Simple editing with PSGML</name>
      
      <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="ed_p1">
	Now you are ready to begin writing CNXML with emacs.  See <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" document="m9000" strength="8">The Basic CNXML</cnxn> for an
	introduction to writing documents in CNXML.  You must begin the
	document with the XML declaration and specifying the document
	type definition to use.  For example, to begin a document using
	CNXML, type the following lines:
      </para>
      
      <example xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="ex_dtd">
	<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" type="block">
<![CDATA[<?xml version="1.0" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5//EN" 
          "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_plain.dtd">]]>
	</code>
      </example>
      
      
      <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="ed_p2">
	Once you have started the file out with this header you can
	begin adding markup elements.  

	<note xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" type="warning">
	  On new documents you will need to enter XML-mode explicitly by
	  entering <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">M-x xml-mode</code>.  ("M" represents
	  the meta key, commonly mapped to 'Alt' on PC keyboards).
	  Once this file is saved, successive editing sessions will
	  bring up xml-mode automatically
	</note>

	You can enter a start tag by typing <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">C-c &lt;
	</code> ("C" represents the control key).  Emacs will then
	prompt you for the tag-name.  Type the name of the tag you
	want, or use TAB-completion.  To insert a close tag for the
	current element, type <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">C-C /</code>.  Emacs will
	automatically close the current tag.  For those who prefer
	menu commands, you can select <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Insert
	Start-Tag</code> or <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Insert End-Tag</code>
	from the <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Markup</code> menu.  Emacs will
	drop-down a list of currently available tags.
      </para>
      
      <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="ed_p3"> Alternatively, to ensure that you have matched
	start and end tags with the appropriate attributes and
	children, you may insert an entire element at once.  To do
	this, type <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">C-c C-e</code> (or select
	<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Insert Element</code> from the menu) and type
	the name of the desired element.  This will insert opening and
	closing tags for the element and prompt you for any required
	attributes.  It will also insert any required child elements.
	Conversely, to delete an entire element with its children,
	type <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">C-M-k</code>.
      </para>
      
      <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="ed_p4">
	There are many other commands that you may find useful.
	Explore the Markup and View menus to get a feel for the
	available commands.  You may also want to look at the 
	reference manual distributed with PSGML.
      </para>
      <section xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="tables">
        <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Adding Tables using Emacs and PSGML</name>
        <para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="tablespara">
	  Another useful feature of emacs is the ability to add tables
	  to your CNXML document quickly and easily.  This requires
	  the emacs <link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" src="http://table.sourceforge.net/">table</link>
	  package to be installed.
	  <list xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="stepslist">
	    <item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Include the following line in your .emacs file:<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">(require 'table)</code></item>
	    <item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
	      Restart emacs, and you'll notice that at the bottom of
	      the <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Tools</code> menu list is a <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Table</code>
	      tool. From there you can insert a table or you can type
	      <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">M-x table-insert</code>.
	    </item>
	    <item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
	      After inserting a table you will be asked questions
	      about the table columns, rows, sizes, etc., specify this
	      information based on your needs.
	    </item>
	    <item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
	      Finally, creating your table you will want to type
	      <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">M-x table-generate-source</code>. When it asks for
	      the language type <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">cals</code>. This will save the
	      file as a <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" document="m9007" target="calstable">CALS
	      table</cnxn> valid document which is the format that
	      CNXML uses. This table can now be cut and pasted into a
	      CNXML document.
	    </item>
	  </list>
        </para>
      </section>
      <section xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="non_english">
	<name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Non-English characters</name>
	<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="unicode">
	  If your CNXML document is not written in English, you will
	  probably need to enter non-English characters.  If you have
	  a non-US keyboard you can simply type the desired characters
	  as you normally would.  Many systems also include a
	  "character picker" of some sort, allowing you to copy
	  occasionally used characters or symbols to the clipboard.
	  You can then paste them into emacs.
	</para>
	<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="iso_accents">
	  <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">iso-accents-mode</name> For accented characters
	  appearing in many western languages, you may want to use
	  emacs' <term xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">iso-accents-mode</term>
	  Just enter the command <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">M-x iso-accents-mode</code>.
	  You can then enter accented characters by typing
	  <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">'</code> (apostrophe) followed by a vowel.  Check the <link xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" src="http://www.cs.tut.fi/~jkorpela/emacs-iso.html">instructions</link>
	  for more details. 
	</para>
      </section>
    </section>
  </content>
  
</document>
