Showing posts with label identifier. Show all posts
Showing posts with label identifier. Show all posts

2009-06-07

Book index

Start small, think big: while I don’t even provide a decent default stylesheet, I’m not afraid to blog about a tough subject: book index.

An index is a table at the end of a book, referencing pages or chapters containing a pertinent usage of a key word.

A very simple kind of index could look like this:

icons, 21, 136, 138

You can have ranges:

gender in language, 4-6

References avoid duplicates:

GUIs, see graphical user interfaces (GUIs)

Words can group on several levels (3 being the maximum):

keys
  capitalizing name of, 68
  typographic conventions for, 144, 147
  writing about, 142

Simplest representation

How could Novelang help to represent this?

The simplest thing to do is to use some kind of delimiter to tell that a word is an index entry. (As usual the meaning of the delimiter would be a matter of stylesheet.)

The {icon} is displayed on the corner.

Obviously, this doesn’t work, because we want the index entry to show a plural. So we invent some new kind of syntactic form representing a tuple (which symbols are used doesn’t matter at this stage).

The { icon | icons } is displayed in the corner.

Great, but how to model several levels of entries? We could make the source document look like this:

In this case we must
{ capitalize | { keys | capitalizing name of } }
the name of a key.

This feels just unreadable!

External index entry declaration

The trick: split index entry declaration from its complete definition, using several files. Complete definition would rely on a subset of Novelang grammar for source files. Example above becomes:

%% source document:

In this case we must
{ capitalize | capitalizing-name-of-key }
the name of a key.


%% index definition file:

capitalizing-name-of-key
- capitalizing name of
  - keys

This deserves a few explainations. The first capitalize in the source document is still what’s displayed. The capitalize-name-of-key is the entry name that is not supposed to be read by anybody else than the document writer – could be 123456 as well. The capitalizing name of in the index definition file is what to display in the index. The keys subitem is the parent item.

Because name of the index entry has no semantic meaning, we can let Novelang generate it using simple replacement rules (spaces becoming hyphen minus…). Explicit names are useful for special cases (like homonyms) but now we expect to be able to write:

%% source document:

In this case we must {capitalize} the name
of a key.


%% index definition file:

capitalize
- keys
  - capitalizing name of

Because for the same index entry we may have another pertinent words which are not exactly “capitalize” we let the index entry support several names.

%% source document place 1:

In this case we must {capitalize} the name
of a key.


%% source document place 2:

Sometime the name of a key should not be
{in capitals}.


%% index definition file:

in-capitals
capitalize
- keys
  - capitalizing name of

The index definition file could support lots of features.Some styling. There are rare cases (like latin names) where italics are required.A kind of markup to tell which words to take in account in alphabetical sort.Multiple posting: the same keyword in the source document has several index entries. This can happen using several embedded list items.“See” and “See Also” references.

Reusing tags and identifiers

Now, entry names may give some feeling of déjà vu. We already have machine-processed names with tags (implemented) and identifiers (not implemented yet). Are entry names just redundant? As tags and identifier apply on a whole paragraph or level, they don’t have the same level of precision when it comes to refer to the exact location of a word. And it turns out that referencing a range of paragraphs (or even chapters) is what we need for supporting page ranges.

The obvious way of handling page range would be to add a new “end of index entry range” here polluting the source document and making it look like LaTeX. This is a convention of the Novelang grammar: avoid end delimiters whenever possible. Tags and identifiers provide a nice extension.

Here is how we use a tag in the index definition file. Instead of tagging, it refers to the tagged text as index entry name:

%% source document:

@gender
== Stylistic principles

=== Avoid jargon

 ...

=== Avoid sexist language

 ...

=== Common gender

 ...


%% index definition file:

@gender
- gender in language

This is not yet perfect because page ranges are bound to the scope of a tag​/​identifier. But it seems possible to Some tree-mangling could detect that several tagged nodes appear consecutively:

%% source document:

== Stylistic principles

=== Avoid jargon

 ...

@gender
=== Avoid sexist language

 ...


@gender
=== Common gender

 ...

Tree-mangling could add a special marker as the last child of the last node of the consecutive tagged ones. Our tree would look like:

level
  + level-title     "Stylistic principles"
  + level
  |   + level-title "Avoid jargon"
  + level
  |   + level-title "Avoid sexist language"
  |   + tag         "gender"
  |   + paragraph
  |   |   + start-of-range "gender"
  |   |   + ...
  |   + paragraph
  + level
      + level-title "Common gender"
      + tag         "gender"
      + paragraph
      + paragraph
         + ...
         + end-of-range    "gender"

Foreseen weaknesses

This is still unperfect because page ranges are bound to the scope of tags​/​identifiers but this looks like a pretty good approximation.

Another possible drawback is the ability to have overlapping ranges or page numbers with several different tags​/​identifiers, or index entries in the middle. Because FOP provides no hook to deal with page numbers once they are known, Novelang could not fix a serie of page numbers like 14-17, 15-18, 15, 16. It’s a long way to perfection.

Bibliography

All examples from A Style Guide for the Computer Industry, Sun Technical Publications, 1996.

2009-02-27

Images

I just checked a first working version of images into github. It’s far from complete, but with such source document:

image:foo/bar.jpg

… the stylesheet receives a n:image element containing foo/bar.jpg. How beautiful. It is supposed to work the way URL do and offer a uniform syntax. It addition, it’s more or less used elsewhere, see http://www.wikicreole.org/wiki/ImagesReasoning.

But it’s crap. It’s wrong, it’s inconsistent, it will not be comfortable.

URL exist on their own line because this makes copy-paste easy. There is no operating system supporting image: as a protocol. And URL are links to another resource, while image:... represents the resource itself.

Other wikis need the image: prefix because they accept a / in the middle of the content. Novelang requires the solidus to appear as literal. Therefore something like screenshots/preferences.png cannot be confused with three words with punctuation signs or symbols inbetween.

Current image support takes paths relative to the project root, but a path relative to current Part file is comfortable in some cases. If the image is in the same directory, we need to make the solidus character appear so we’ll have ./preferences.png (instead of preferences.png which could be two dot-separated words).

The extension is enough to make the difference with other resources. Almost everybody knows that .jpg, .png, .gif, .svg are for images, and it leaves room for other stuff like .csv.

In a previous post about tables, I stated that image declaration would be too long to fit in a cell, but with relative path and no image: prefix this has to be revised.

Images are definitely not the same thing as URL, but the decorations should work the same way, with an identifier and a name.

Then, the identifier could replace the image, or provide some kind of reference. I’ll tell more about identifiers another day but here’s a complete example using two different source files.

First file: we declare the image, decorating it with metadata.

  \dog-with-bone
  "My dog with its bone"
/photos/dog.jpg

Second file: using images declared above.

See a picture of my dog:

\dog-with-bone

... later in the text, we want some reference to the 
picture to appear, like its name, some hyperlink or 
a figure number (depending on the stylesheet). 

You have already seen my dog in -\dog-with-bone .

Finally, it seems we’ve the best of every world with a compact notation.

2008-08-04

Decorations revisited

On the previous post about URLs we extended the decoration concept to URLs. We stated that some identation tells "this is a decoration for the construct right below". As this impacts the way to define identifiers here is an updated example, with 4-space indentations.
    \\chapter-one-identifier
    @tag-1
== Chapter one

    \section-one-identifier
    @tag-1 @tag-2
=== Section one

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Nunc vulputate, elit ac accumsan sodales, libero nisi 
euismod erat, a semper dolor turpis non pede. 
Donec sem ligula, congue id, porta et, tincidunt quis, 
eros. Praesent ipsum. Ut at urna. Proin cursus condimentum
risus. Fusce at lacus tincidunt 
    "here"
    [Visit Novelang website]
    \\novelang-website
http://novelang.sf.net
metus tristique dictum. Pellentesque habitant morbi 
tristique senectus et netus et malesuada fames ac turpis 
egestas. Suspendisse potenti. Aliquam id quam. Quisque 
pellentesque est vitae est. Morbi faucibus ornare ligula. 
Pellentesque sed mi non elit vehicula ullamcorper. 
Pellentesque habitant morbi tristique senectus et netus 
et malesuada fames ac turpis egestas. Nunc vel eros nec 
leo mollis adipiscing.

    \paragraph-identifier
Pellentesque mollis, quam et tincidunt vulputate, ligula 
lectus ullamcorper lacus, non sagittis lorem lectus ut 
tellus.Praesent diam mi, convallis et, pharetra sed, 
tempus in, lacus. Integer aliquet, augue ac vestibulum 
sollicitudin, ligula erat molestie eros, sed feugiat diam 
felis et odio.


    \section-two-identifier
    @tag-2
=== Section two

In orci elit, porta id, volutpat ac, ornare sit amet, 
felis. Mauris vel ipsum eget mi gravida pellentesque. 
Vestibulum et pede et mi lobortis cursus. 
Phasellus fermentum, odio non auctor placerat, nisi pede 
aliquam nisi, in ultrices leo mi vitae risus. 
Lorem ipsum dolor sit amet,  
    "consectetuer adipiscing elit"
url-ref: \\novelang-website
. Quisque eu neque ac lectus consectetuer pharetra. Nulla 
rhoncus elementum mi. Phasellus vitae diam. Class aptent 
taciti sociosqu ad litora torquent per conubia nostra, per 
inceptos himenaeos. Sed bibendum, sem nec consectetuer 
laoreet, ante felis aliquam metus, non placerat nunc erat 
vitae dolor. 

URL syntax

By now URLs must appear as a standalone paragraph. This is correct:
Go to:

http://novelang.sourceforge.net

And see all useful links.
But this is incorrect:
Go to http://novelang.sourceforge.net and see all useful links.
There is a good reason to keep the URL on its own line: most text editors make easy to copy a whole text line, so there is less chance to forget some characters when moving the URL inside the text or copy-pasting it to a Web browser. Aside of this, "http", ":" and "//" are legal Novelang grammar constructs (as word, punctuation sign, and start of italics, respectively) so a hint on where to find a URL makes the Novelang grammar much simpler. I've looked at the way Markdown and WikiCreole define hyperlinks. Both require too many delimiters; I prefer to leverage on the fact a URL takes place on its own line. The good thing to keep from Markdown is labelling (give a label to some URL and reuse it later through this label); one day Novelang will do the same through identifiers. So let's say this could become legal:
Go to 
http://novelang.sourceforge.net
and see all useful links.
There are at least two features missing: text for URL and advisory title (the one appearing in a tooltip). URL text and advisory title are about "decorating" some Novelang construct. This was previously discussed for identifiers. We could get something like:
Go to 
  "Novelang website" 
  [Novelang website on Sourceforge.net]
http://novelang.sourceforge.net
and see all useful links.
I don't want to use new delimiters for URL text and advisory title, in order to not transform Novelang grammar to some new flavor of XML. So let's say double quotes are for URL text and square brackets for advisory title. As a good news, this notation is consistent with the way to decorate paragraphs with identifiers. This strengthens the meaning of indentation as "here stands metadata stuff for the thing right below". So we're breaking previous decision to put chapter and section decorations below the header. It's amazing to see, how keeping consistency on a grammar carries the showckwave of small changes on long distances: here it was about adding URL text and now we're revising the way we write chapter and section headers.

2008-06-12

Images

My goal is to not introduce syntax constructs into Novelang for every need, but handling images with paired delimiters quickly becomes a mess. So image: syntax is fine but it collides with what a plain Paragraph can be made of. Let's twist it a bit using a double colon for now.
image::path/file.ext
As with URLs it seems more readable to force image declaration to start at the beginning of a line. The all-on-the-same-line requirement comes with the same advantages: it's easy to add metadata.
image::path/file.ext "title"
There are several ways to reference an image: the image itself for displaying it, or its name. Many document have textual references to images (like Fig. 5). Numbering must be automated, and text must reference images through a symbolic name. It's a clear need for identifiers. Defining identifiers works the same as for Paragraphs:
  \\image-identifier
image::path/file.ext "title"
Referencing the image is done with a new image-ref:: keyword, that should appear at the start of a new line, too:
Have a look at
image-ref::\\image-identifier
.
Ok I'm not happy with the full stop coming on its own line but I'm just trying to be honest so don't hit me. Depending on numbering scheme this should translate to something like:
Have a look at Figure 5-12.
Image display can happen through a reference, too:
image::\\image-identifier
With all that in mind, here is how to use images in big documents. Define one Part file or more with all images, then reference them as needed. The Part files containing images may define Sections with their own absolute identifiers corresponding to some themes or categories, and all images inside the Sections have a relative identifier. Another advantage of having all images in separate files is to get an overview for free.

More on identifiers

Since I've been blogging on identifiers something came to my mind. There are absolute identifiers (for Chapters and Sections) and relative ones (for paragraphs). The syntax should reflect this. What about :
  \\absolute-identifier

  \relative-identifier
The reverse solidus (well-known of Windows users) is convenient for expressing path-like structures, while not conflicting with the solidus used in URLs. A relative identifier requires an absolute identifier. For a Part like this:
== Section
  \\section-identifier

  \paragraph-identifier-1
Blah. 

  \paragraph-identifier-2
Blah blah. 

  \paragraph-identifier-3
Blah blah blah. 

Here is a valid reference to the paragraph:
\\section-identifier\paragraph-identifier
The absolute identifier may be carried by the context. As described in the Book post, only some Paragraphs in a Section may be included so referencing the Section is a way to define such a context.
expand \\section-identifier
  \paragraph-identifier-1
  \paragraph-identifier-3
Ok the syntax has slightly evolved since but you get the idea. The reverse-solidus based notation looks good to me. Double path separator for an absolute path is a well-known pattern (URL spec). I like the idea to ask a bit more work for an absolute identifier as they should be used carefully, in order to avoid global namespace pollution. With that syntax we now support an uniform relationship model between Chapters, Sections and Paragraphs.

2008-05-22

Better identifiers

The Book feature described in the previous post relies on identifiers for Chapters, Sections and paragraphs. Now let see how to set an identifier in a Part file. Paragraphs have special identifiers in the sense they must be unique inside the whole Section, not inside the whole Book. But the semantic must remain the same -- just use a different marker. Decorations (additional information) for a Chapter / Section can take place right below the element.
*** My Chapter
#some-identifier-here

[Sections and paragraphs follow]
But Paragraphs don't have nested elements so the nesting rule is somewhat violated. Decoration for a Paragraph must look like this:
§some-paragraph-identifier
This is my paragraph.
Placing the decoration above the Chapter / Section delimiter would be consistent but I find it less readable:
#some-chapter-identifier
*** My Chapter

#some-section-identifier
=== My Section

§some-paragraph-identifier
My Paragraph.
There is another feature I never talked about: Tags. This is for adding even more decorations to those elements.
#some-chapter-identifier
@Tag-one @Tag-two
*** My Chapter

#some-section-identifier
@Tag-one
=== My Section

§some-paragraph-identifier
@Tag-three @Tag-four
My Paragraph.
That seems pretty unreadable now but the case above is not realistic. And indentations can be added to differenciate decorating stuff. Real-world example rather looks like this:
  #some-chapter-identifier
@Tag-one @Tag-two
*** My Chapter

  #some-section-identifier
  @Tag-one
=== My Section

  §some-paragraph-identifier
  @Tag-three @Tag-four
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque
tortor justo, blandit at, tincidunt sed, blandit et, dolor. Donec pede
massa, cursus sed, ornare et, volutpat non, mi. In pede. Nullam
hendrerit tellus vitae justo. Etiam et massa in dolor scelerisque
faucibus. Praesent libero ante, ultrices eu, egestas ac, interdum in,
dolor. Phasellus sit amet tellus eget metus ultricies suscipit. Nam sed
neque sit amet neque gravida bibendum. Cras elementum. Suspendisse
potenti.
I definitely don't like decorations above Chapters and Elements. Let's see how it looks when placing them below:
*** My Chapter
  #some-chapter-identifier
  @Tag-one @Tag-two

=== My Section
  #some-section-identifier
  @Tag-one
 
  §some-paragraph-identifier
  @Tag-three @Tag-four
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque
tortor justo, blandit at, tincidunt sed, blandit et, dolor. Donec pede
massa, cursus sed, ornare et, volutpat non, mi. In pede. Nullam
hendrerit tellus vitae justo. Etiam et massa in dolor scelerisque
faucibus. Praesent libero ante, ultrices eu, egestas ac, interdum in,
dolor. Phasellus sit amet tellus eget metus ultricies suscipit. Nam sed
neque sit amet neque gravida bibendum. Cras elementum. Suspendisse
potenti.
That's definitely better. Let's say that Paragraph identifiers is a marginal case. Let's say that it's pretty uncommon to have identifiers for Chapters and Sections because if you want to pick the whole Chapter it's unusual to pick some Sections inside. And let's avoid identifiers whenever possible : that will reduce bloat and do less typing. Let's say a Section / Chapter title can be referenced as an identifier when unique in the whole Book scope. The ::add syntax supports almost any character so a title with spaces and nested text (like parenthesis) is ok. Now let's do the mix:
*** My Chapter
  @Tag-one @Tag-two

=== My Section
  #some-section-identifier @Tag-one

  §1
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque
tortor justo, blandit at, tincidunt sed, blandit et, dolor. Donec pede
massa, cursus sed, ornare et, volutpat non, mi. In pede. Nullam
hendrerit tellus vitae justo. Etiam et massa in dolor scelerisque
faucibus. Praesent libero ante, ultrices eu, egestas ac, interdum in,
dolor. Phasellus sit amet tellus eget metus ultricies suscipit. Nam sed
neque sit amet neque gravida bibendum. Cras elementum. Suspendisse
potenti.
That looks pretty readable to me.