From: jjc@jclark.com (James Clark)
Subject: Re: PSGML -- A more readable SGML
Organization: None, London, England
Date: 8 Apr 92 14:10:15

In article <1992Apr5.023007.23419@cco.caltech.edu> rebecca@cco.caltech.edu (Mark L. Fussell) writes:

   ...
   So here is part of the QWERTZ DTD and the (slightly
   modified) title again, if you want to try:

   <!--=========================================================-->
   <!element titlepag o o (title, author)>
   <!element title - o (%inline, subtitle?) +(newline)>
   <!element subtitle - o (%inline)>
   <!element author - o (name, thanks?, inst?, 
			   (and, name, thanks?, inst?)*)>
   <!element name o o (%inline) +(newline)>
   <!element and - o empty>
   <!element thanks - o (%inline)>
   <!element inst - o (%inline) +(newline)>
   <!entity nl "<newline>"> 
   <!entity QWERTZ "<tt/qwertz/"> 
   <!--========================================-->
   <title>The &QWERTZ; SGML Document Types   
   <subtitle>(Version 1.1 Reference Manual)
   <author>Tom Gordon
   <inst>The &QWERTZ; Project &nl
   Institute for Applied Information Technology (F3) &nl&nl
   German National Research Center &nl 
   for Computer Science (GMD)
   <!--=========================================================-->

   ...
   Running the original file and PSGML->SGML file through SGMLS
   gives the following differences between them:

       <ORIGINAL - SGML Document Types   \n|
       ---
       >PSGML    - SGML Document Types|

       <ORIGINAL - Project |
       ---
       >PSGML    - Project|

       <ORIGINAL -Institute for Applied Information Technology (F3) |
       ---
       >PSGML    -Institute for Applied Information Technology (F3)|

       <ORIGINAL -German National Research Center |
       ---
       >PSGML    -German National Research Center|

       <ORIGINAL - \nfor Computer Science (GMD)|
       ---
       >PSGML    -for Computer Science (GMD)|


   The vertical bar at the end of each line is to mark the
   trailing spaces on a few of them.  These differences show
   the "errors" that were in the original file: spaces at the
   ends of lines, and the problem with putting the subtitle on
   its own line.  The single spaces at the end of several lines
   is not important in this case, but they might be in other
   contexts.  They were visible anyway, so SGML can not be
   blamed.  The spaces and newlines are more serious though:
   we were specifying a title, which should not have any spaces
   at the end (so it will center properly, if so desired) and 
   certainly should not have a newline in it.  Neither should 
   the institute's last line have a space and '\n' beginning it.
   But these problems can't be seen, and require understanding
   exactly how the DTD is interpretted by SGML.

You've missed out a crucial part of the DTD.  Here's a simplified
version that shows what's going on:

<!doctype titlepag [
<!element titlepag o o (title, author)>
<!element title - o (#pcdata, subtitle?)>
<!element subtitle - o (#pcdata)>
<!element author - o (#pcdata)>

<!entity space " ">
<!shortref oneline "&#RS;" space>
<!usemap oneline titlepag>
]>
<title>title
<subtitle>subtitle
<author>author

sgmls produces:

(TITLEPAG
(TITLE
-title\n |
(SUBTITLE
-subtitle\n |
)SUBTITLE
)TITLE
(AUTHOR
-author|
)AUTHOR
)TITLEPAG

(I've added vertical bars to show trailing spaces.)

The short reference map is the main culprit.  Getting rid of the map
changes this to:

(TITLEPAG
(TITLE
-title\n|
(SUBTITLE
-subtitle|
)SUBTITLE
)TITLE
(AUTHOR
-author|
)AUTHOR
)TITLEPAG

This is better, but the newline at the end of the title is still
undesirable.  However, if the DTD is modified like this,

<!doctype titlepag [
<!element titlepag o o (titlegrp, author)>
<!element titlegrp o o (title, subtitle?)>
<!element title - o (#pcdata)>
<!element subtitle - o (#pcdata)>
<!element author - o (#pcdata)>
]>

then there are no extra newlines:

(TITLEPAG
(TITLEGRP
(TITLE
-title|
)TITLE
(SUBTITLE
-subtitle|
)SUBTITLE
)TITLEGRP
(AUTHOR
-author|
)AUTHOR
)TITLEPAG

James Clark
jjc@jclark.com