How to maintain a notebook with Lyx/latex

2 minute read

Published:

This post details how I maintain with Lyx/latex my notebook, with each chapter dedicated to a subject of interest.

Purpose

The wanted notebook is a pdf file with hyperlinked cross-references and citations. Each chapter has its own bibliography. The maintaining and updating work should be simple and clear. Since my notes on physics and mathematics usually contain a lot of long equations, Lyx is used to visualize these equations for the ease of initial coding and subsequent modifications.

Directory Structure

The directory structure is shown here

zhou.sty contains the definitions I use for almost all works with latex. Notes contains all my notebooks, such as NotesComputerTech and NotesTheoreticalPhysics. /Notes/definitions/myNotes.cls and /Notes/definitions/myNotes.layout define the layout/documentclass myNotes which is used for all my notebooks. These two layout/documentclass files are copied to the layouts in the user directory of Lyx (see in the software Lyx → about lyx).

Take NotesTheoreticalPhysics for example. It contains the main NotesTheoreticalPhysics.lyx file and chapters of ClassicalMechanics, Electrodynamics, FluidMechanics, PlasmaPhysics and so on. Each chapter contains a main lyx file and the associated figures and preamble.txt. The chapter lyx file can run independently to produce a pdf file. In the NotesTheoreticalPhysics.lyx file, all chapters are included/input.

The preamble.txt at notebook level input all preambles at chapter level. To generate these preambles automatically, run the python script preambleConfig.py.

Lyx and layout/documentclass file

To make the change in layout/documentclass file take effect in Lyx, run in Lyx tools → reconfigure and restart the software.

Bibliography

By default, myNotes.cls uses the package bibunits to divide bibliographies across chapters, with

    \bibliographyunit[\chapter]
    \defaultbibliography{/Users/yufei/Documents/MyFiles/myLib}
    \defaultbibliographystyle{plain}

hard-coded into the cls file. To put a bibliography in a chapter, use \putbib. The native lyx utilities to divide bibliographies should be avoided, as they are broken at large!. To make bibunits work with hyperref, the code in this file is put in the class file. Lyx does not work well with bibunits as it does not automatically run bibtex on the separate bib files generated by bibunits. To make it so, the following line is added to the class file.

    \renewcommand{\@bibunitname}{\jobname.\the\@bibunitauxcnt}

TexStudio run

In TexStudio automatically run bibtex on bib files generated by bibunits, use latexmk instead of xelatex. I have modified the latexmk command to

    latexmk -xelatex -silent -synctex=1 -interaction=nonstopmode