1[/ 2 Copyright 2002,2004,2006 Joel de Guzman, Eric Niebler 3 Copyright 2010-2011 Daniel James 4 5 Distributed under the Boost Software License, Version 1.0. 6 (See accompanying file LICENSE_1_0.txt or copy at 7 [@http://www.boost.org/LICENSE_1_0.txt]) 8] 9 10[chapter Document Structure 11 [quickbook 1.7] 12 [id quickbook.syntax.structure] 13 [source-mode teletype] 14] 15 16[/TODO: I started to write this in the syntax chapter, but it was too 17much information, will incorporate into this file.] 18[/ 19To avoid breaking old documentation we support using different versions 20of the language, compatibility is not 100% but we try to avoid 21problematic changes. This documentation applies to the current version, 22`[quickbook 1.5]`. 23] 24 25[#quickbook.ref.docinfo] 26[section:docinfo Document Info] 27 28Every document must begin with a Document Info section, which looks something 29like this: 30 31``` 32[article The Document Title 33 [quickbook 1.7] 34 [version 1.0] 35 [id the_document_name] 36 [copyright 2000 2002 2003 Joe Blow, Jane Doe] 37 [authors [Blow, Joe] [Doe, Jane]] 38 [license The document's license] 39 [source-mode c++] 40] 41``` 42 43`article` is the document type. There are several possible document types, 44most of these are based on docbook document elements. These are fully 45described in 46[@http://www.docbook.org/tdg/ DocBook: The Definitive Guide]: 47 48* [@http://www.docbook.org/tdg/en/html/book.html book] 49* [@http://www.docbook.org/tdg/en/html/article.html article] 50* [@http://www.docbook.org/tdg/en/html/chapter.html chapter] 51* [@http://www.docbook.org/tdg/en/html/part.html part] 52* [@http://www.docbook.org/tdg/en/html/appendix.html appendix] 53* [@http://www.docbook.org/tdg/en/html/preface.html preface] 54* [@http://www.docbook.org/tdg/en/html/qandadiv.html qandadiv] 55* [@http://www.docbook.org/tdg/en/html/qandaset.html qandaset] 56* [@http://www.docbook.org/tdg/en/html/reference.html reference] 57* [@http://www.docbook.org/tdg/en/html/set.html set] 58 59Boostbook also adds another document type [^[link boostbook.defining library]] 60for documenting software libraries. 61 62So the documentation for the 'foo' library might start: 63 64``` 65[library Foo 66 [quickbook 1.7] 67 [id foo] 68 [version 1.0] 69] 70``` 71 72[#quickbook.ref.attributes] 73[section:attributes Document Info Attributes] 74 75The document info block has a few different types of attributes. 76They are all optional. 77 78[heading Quickbook specific meta data] 79 80``` 81 [quickbook 1.7] 82``` 83 84The `quickbook` attribute declares the version of quickbook 85the document is written for. 86In its absence, version 1.1 is assumed. It's recommended that 87you use `[quickbook 1.7]` which is the version described here. 88 89[note 90 91The quickbook version also makes some changes to the markup 92that's generated. Most notably, the ids that are automatically 93for headers and sections are different in later versions. To 94minimise disruption, you can use the =compatibility-mode= 95attribute to generate similar markup to the old version: 96 97``` 98[article Article that was original 99 written in quickbook 1.3 100[quickbook 1.7] 101[compatibility-mode 1.3] 102] 103``` 104 105This feature shouldn't be used for new documents, just for 106porting old documents to the new version. 107] 108 109Both the =quickbook= and =compatibility-mode= tags can be used 110at the start of the file, before the document info block, and 111also in files that don't have a document info block. 112 113``` 114 [source-mode teletype] 115``` 116 117The `source-mode` attribute sets the initial __source_mode__. If 118it is omitted, the default value of =c++= will be used. 119 120[heading Boostbook/Docbook root element attributes] 121 122``` 123[id foo] 124``` 125 126`id` specifies the id of the document element. If it isn't specified 127the id is automatically generated from the title. This id is also 128used to generate the nested ids. 129 130``` 131[lang en] 132``` 133 134`lang` specifies the document language. This is used by docbook to 135localize the documentation. Note that Boostbook doesn't have any 136localization support so if you use it to generate the reference 137documentation it will be in English regardless. 138 139It should be a language code 140drawn from ISO 639 (perhaps extended with a country code drawn from 141ISO 3166, as en-US). 142 143``` 144[dirname foo] 145``` 146 147`dirname` is used to specify the directory name of the library in the 148repository. This is a boostbook extension so it's only valid for 149`library` documentation blocks. It's used for some boostbook 150functionality, but for pure quickbook documentation has no practical 151effect. 152 153[heading Docbook Metadata] 154 155=version=, =copyright=, =authors=, 156=license=, =last-revision= and =bibliod= are optional information. 157 158[heading Boostbook Metadata] 159 160=purpose= and =category= are boostbook attributes which are only 161valid for =library= documents. If you use them for other document types, 162quickbook will warn about them, but still use them, generating invalid markup, 163that's just ignored by the style sheets. 164 165[heading:escaped-docbook Escaped Docbook] 166 167From quickbook 1.7 onwards, 168[link quickbook.ref.escape escaped boostbook or docbook] 169can be included in a docinfo block: 170 171``` 172[article Some article 173[quickbook 1.7] 174'''<author> 175 <firstname>John</firstname> 176 <surname>Doe</surname> 177 <email>john.doe@example.com</email> 178</author>''' 179] 180``` 181 182The escaped docbook is always placed at the end of the docinfo block, 183so it shouldn't be assumed that it will interleave with markup generated from 184quickbook. A mixture 185of quickbook and docbook attributes for the same information will not work 186well. 187 188[endsect:attributes] 189 190[section:nesting Nesting quickbook documents] 191 192Docinfo blocks can only appear at the beginning of a quickbook file, so to 193create a more complicated document you need to use several quickbook files and 194use the [link quickbook.ref.include include tag] to nest them. For example, say 195you wish to create a book with an introduction and a chapter, you first create 196a file for the book: 197 198 [book Simple example 199 [quickbook 1.7] 200 ] 201 202 [include introduction.qbk] 203 [include chapter.qbk] 204 205[note Structuring a document like this was introduced in quickbook 1.6, so a 206`[quickbook 1.6]` or later docinfo field is required.] 207 208The appropriate document type for an introduction is `preface`, so 209the contents of `introduction.qbk` should be something like: 210 211 [preface Introduction 212 [quickbook 1.7] 213 ] 214 215 Write the introduction to the book here.... 216 217And `chapter.qbk`: 218 219 [chapter A chapter 220 [quickbook 1.7] 221 ] 222 223 Chapter contents.... 224 225[endsect:nesting] 226 227[endsect:docinfo] 228 229[#quickbook.ref.section] 230[section:section Sections] 231 232Quickbook documents are structured using 'sections'. These are used 233to generate the table of contents, and, when generating html, to 234split the document into pages. This is optional but a good idea for 235all but the simplest of documents. 236 237A sectioned document might look like: 238 239``` 240 [book Title 241 [quickbook 1.5] 242 ] 243 244 [section First Section] 245 246 [/...] 247 248 [endsect] 249 250 [section Second Section] 251 252 [/...] 253 254 [endsect] 255``` 256 257Sections start with the `section` tag, and end with the `[endsect]` tag. 258(`[/...]` is a comment, [link quickbook.ref.comments described later]). 259 260Sections can be given an optional id: 261 262``` 263[#quickbook.ref.id] 264[section:id The Section Title] 265``` 266 267`id` will be the filename of the generated section. 268If it is not present, "The Section Title" will be normalized and become the id. 269Valid characters are =a-Z=, =A-Z=, =0-9= and =_=. All non-valid characters are 270converted to underscore and all upper-case are converted to lower case. 271Thus: "The Section Title" will be normalized to "the_section_title". 272 273The end of the section can also have an optional id, this is just used to 274check that it matches the opening of the section. 275 276``` 277[section:matching Section with an id] 278 279[/...] 280 281[endsect:matching] 282``` 283 284It won't match a generated id, only one that's explicitly specified, so 285this will be an error, even if quickbook generates the id `generated` 286for the section: 287 288``` 289[section Generated] 290 291[/...] 292 293[endsect:generated] 294``` 295 296Sections can nest, and that results in a hierarchy in the table of contents. 297 298[endsect:section] 299