3. “Hello world!” using lyx

3.1. Why use lyx to produce SGML?

lyx provides an easy way to produce an SGML document. If you can use a word processor you will find lyx very easy to pick up. You can find a lot of information about SGML in the newbieDoc DocBook Guide (http://newbiedoc.sourceforge.net/metadoc/docbook-guide.html).

3.2. Getting started using a newbieDoc template

Open a new document from lyx's menu bar.

Menu bar:     File -> New from Template -> newbiedoc-lyx-template.lyx -> OK 
   

3.3. lyx layouts and the list of styles

Using lyx is very like using a word processor. It operates on paragraphs - you create a paragraph every time you press the <ENTER> key. Section headings are often called 'commands' by lyx. Body text is usually either an 'environment' or a 'paragraph'. It is easiest just to think of them all as paragraphs.

Each paragraph is formatted in a particular lyx style. You chose the style form the drop-down list of styles in the top left-hand corner of the lyx window. A 'layout' is a collection of styles.

3.4. Modify the document information

Substitute your own information in the template's place-holders:

3.5. Add the content using lyx styles

This is how to produce a simple article with only one section and one paragraph of standard text. Position the insertion point (flashing vertical bar) at the end of the document. Create a new line by pressing the <ENTER> key.

Select 'Section' from the list of styles. The drop-down styles list is the left-most button in the button bar. Enter the title 'Hello world message' (without the quotes) and press the <ENTER> key.

Drop-down styles list:    Section

LyX main window:    Hello world message
   

Enter a short paragraph using the Standard style. (Standard is the default style, so just go ahead and type.)

Drop-down styles list:   Standard

LyX main window:   Hello world!
   

That's it! Remember to save the file (hello-world.en.lyx).

Menu bar:   File -> Save -> hello-world.en -> Save
   

3.6. Generate and view SGML code

Generate DocBook SGML using lyx's 'Export' command. From the menu bar:

Menu bar:     File -> Export -> DocBook
   

lyx produces a file with the same name (hello-world.en ) but with a .sgml extension in the same directory as the lyx source file. You can view hello-world.en.sgml with a text editor:

<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
<article lang="en"> <!-- DocBook file was created by lyx 1.3 See http://www.lyx.org/ for more information -->
<!--newbiedoc-lyx-template.en.lyx, newbiedoc-lyx-template.en.sgml (version 0.01), Copyright (c) March 2004 Chris Lale <feedback.chrislale@coolscience.co.uk>. Permission is granted to copy, distribute and/or modify this document with no Invariant Sections, with no Front-Cover texts and with no Back-Cover Texts under the terms of the GNU Free Documentation License, version 1.1 or any later version, published by the Free Software Foundation. A copy of the license can be found at http://www.fsf.org/copyleft/fdl.html. -->
   <title> Page header (except first page) </title> 
   <articleinfo> 
     <title> Article title </title> 
     <author> 
         <firstname> Your-firstname </firstname> 
         <surname> Your-surname </surname> 
         <affiliation>
            <address> 
               <email> your-account@your-provider </email>
            </address>
         </affiliation>
      </author>
      <revhistory>
         <revision> 
            <revnumber> 0.01 </revnumber> 
            <date> 8 March 2004 </date> 
            <authorinitials> xx </authorinitials> 
            <revremark> Eg Initial release; brief note of changes to previous version.</revremark>
<!-- Insert subsequent revision information here. (Add these lyx layouts: Revision, Date, Initials and RevisionRemark.) -->
         </revision>
      </revhistory>
      <abstract> 
         <para> This is a short summary. It should include a statement such as: known to work with Debian 3.0 (Woody). </para>
      </abstract>
   </articleinfo>
   <sect1> 
      <title> Hello world message </title> 
         <para> Hello world! </para>
   </sect1>
</article>
   

lyx has added the DTD (Document Type Declaration) at the top. Then it has declared an article written in English (lang=”en”). It has also added a comment to say that this is a DocBook file created by lyx.

The article's header is contained between <title></title> tags, and the article title is between <articleinfo><title></title></articleinfo> tags.

The section's title is contained by <title></title> tags, and the following standard text is contained by <para></para> tags. Both these containers are contained within <sect1></sect1> first-level section tags. Finally, the whole article is contained by <article></article> tags.

3.7. Generate and view the HTML web page

You can transform your .sgml file into a number of different formats by using sgmltools-lite. (If you want to know more, read about sgmltools' back-ends in its manual - the command is man sgmltools.)

Open a terminal window (eg gnome terminal). Move to the directory containing both ( hello-world.en.lyx and hello-world.en.sgml). Execute this command:

$ sgmltools -b onehtml hello-world.en.sgml
   

The result is another file in your working directory. The new file is hello-world.en.html and you can view it in a web browser. The HTML article has only one section: “Hello world message”.

Web browser:    File -> Open -> hello-world.en.html -> OK

Hello world message
Hello world! 
   

3.8. Generate HTML using the dsssl style-sheet

You can make your document look just like those on the newbieDoc website. Use sgmltools as before but specify the newbiedoc-onehtml.dsl style-sheet.

sgmltools -b onehtml -s newbiedoc-onehtml.dsl hello-world.en.sgml
   

The new web page should now include a table of contents.

Web browser:    View -> Reload

Table of Contents
1. Hello world message
1. Hello world message
Hello world!