Building Scientific Web Books by Martin Otter

Appendix A - makeWebBook Program

In this section the makeWebBook programm is shortly sketched. It is implemented in the Go programming language from Google. The reason for this is explained in the next section. I used additionally the (simple) Integrated Development Environment LideIDE which makes developing with Go very convenient and fast.

A.1 The Go Progamming Language

The programming language Go is developed since 2009 by Google. Its current version is 1.5 (from August 2015). I used Go to implement the makeWebBook program for the following reasons:

Go has the following drawbacks:

The alternative to Go would have been to use the Rust language from Mozilla. The design seems to be similar (e.g. also the Rust executables are large). I did not spend too much time on a comparison. The major reason to use Go was because it is from Google and the syntax of Go looks nicer to me (on first view Rust looks a bit like a functional programming language and I do not like this syntax and the very short abbreviations; e.g. in Modelica a function is called "function", in Go it is called "func" and in Rust it is called "fn". Rust does not have garbage collection, but it is still claimed to be "safe", and has support for generics).

A.2 The Go Implementation of the makeWebBook Program

The program consists of two phases:

  1. In a first phase all files defined in configuration.json under "SectionsFileNames" are read and analyzed with functions of the goquery package. As a result two data structures are constructed:
    • BookStructure.Sections is made to construct afterwards the "Table-of-Contents". It contains the structure of the whole document in a hierarchical form (independently in which file an element is stored). Especially, there is an entry for all section, figure, table and equation elements. In this phase, the numbering is checked and if a number is missing or needs to be updated, then the updated element information is stored in BookStructure.Sections. If an element is modified, this is marked with a flag.
    • BookStructure.SectionFiles is made to update the files afterwards. Therefore, information about all elements that need to be searched and potentially modified in a file are stored in a sequential way. For every element to potentially inspect the start and end tag is stored. Furthermore, it is marked whether the file needs to be modified.
  2. In a second phase all files that are marked as "need to be modified" are copied to the backup directory and then the file is newly constructed in the book directory. This is performed in a simple way: The file is opened as a byte vector and then all the element start tags stored in BookStructure.SectionFiles are searched in the defined order. Once an element start tag is found, and the element needs to be modified, then the element (from start to end tag) is newly constructed and stored on file. All parts of the byte vector that need no modification are just copied to the newly constructed file.