Creating outlines for djvu documents

Often times when you download questionably sourced textbooks, they will not come with an outline. It turns out it is very simple to create one, using only djvulibre. All that is required is to create a text file containing chapter names, and numbers as S-expressions. Each section can also have subsections. For example, here is the outline I wrote for my djvu copy of Rudin's Principles of Mathematical Analysis:

(bookmarks
 ("Table of Contents" "#4" )
 ("Preface" "#8" )
 ("1 The Real and Complex Number Systems" "#10" 
    ("Introduction" "#10")
    ("Ordered Sets" "#12")
    ("Fields" "#14")
    ("The Real Field" "#17")
    ("The Extended Real Number System" "#20")
    ("The Complex Field" "#21")
    ("Euclidean Spaces" "#25")
    ("Appendix" "#26")
    ("Exercises" "#30")
 )
 ("2 Basic Topology" "#33"
    ("Finite, Countable, and Uncountable Sets" "#33")
    ("Metric Spaces" "#39")
    ("Compact Sets" "#45")
    ("Perfect Sets" "#50")
    ("Connected Sets" "#51")
    ("Exercises" "#52")
 )
 ("3 Numerical Sequences and Series" "#56" 
    ("Convergent Sequences" "#56")
    ("Subsequences" "#60")
    ("Cauchy Sequences" "#61")
    ("Upper and Lower Limits" "#64")
    ("Some Special Sequences" "#66")
    ("Series" "#67")
    ("Series of Nonnegative Terms" "#70")
    ("The Number e" "#72")
    ("The Root and Ratio Tests" "#74")
    ("Power Series" "#78")
    ("Summation by Parts" "#79")
    ("Absolute Convergence" "#80")
    ("Addition and Multiplication of Series" "#81")
    ("Rearrangements" "#84")
    ("Exercises" "#87")
 )
 ("4 Continuity" "#92"
    ("Limits of Functions" "#92")
    ("Countinuous Functions" "#94")
    ("Continuity and Compactness" "#98")
    ("Continuity and Connectedness" "#102")
    ("Discontinuities" "#103")
    ("Monotonic Functions" "#104")
    ("Infinite Limits and Limits at Infinity" "#106")
    ("Exercises" "#107")
 )
 ("5 Differentiation" "#112"
    ("The Derivative of a Real Function" "#112")
    ("Mean Value Theorem" "#116")
    ("The Continuity of Derivatives" "#117")
    ("L'Hospital's Rule" "#118")
    ("Derivatives of Higher Order" "#119")
    ("Taylor's Theorem" "#119")
    ("Differentiation of Vector-valued Functions" "#120")
    ("Exercises" "#123")
 )
 ("6 The Riemann-Stieltjes Integral" "#129"
    ("Definition and Existence of the Integral" "#129")
    ("Properties of the Integral" "#137")
    ("Integration and Differentiation" "#142")
    ("Integration of Vector-valued Functions" "#144")
    ("Rectifiable Curves" "#145")
    ("Exercises" "#147")
 )
 ("7 Sequences and Series of Functions" "#152"
    ("Discussion of Main Problem" "#152")
    ("Uniform Convergence" "#156")
    ("Uniform Convergence and Continuity" "#158")
    ("Uniform Convergence and Integration" "#160")
    ("Uniform Convergence and Differentiation" "#161")
    ("Equicontinuous Families of Functions" "#163")
    ("The Stone-Weierstrauss Theorem" "#168")
    ("Exercises" "#174")
 )
 ("8 Some Special Functions" "#181"
    ("Power Series" "#181")
    ("The Exponential and Logarithmic Functions" "#187")
    ("The Trigonometric Functions" "#191")
    ("The Algebraic Completeness of the Complex Field" "#193")
    ("Fourier Series" "#194")
    ("The Gamma Function" "#201")
    ("Exercises" "#205")
 )
 ("9 Functions of Several Variables" "#213"
    ("Linear Transformations" "#213")
    ("Differentiation" "#220")
    ("The Contraction Principle" "#229")
    ("The Inverse Function Theorem" "#230")
    ("The Implicit Function Theorem" "#232")
    ("The Rank Theorem" "#237")
    ("Determinants" "#240")
    ("Derivatives of Higher Order" "#244")
    ("Differentiation of Integrals" "#245")
    ("Exercises" "#248")
 )
 ("10 Integration of Differential Forms" "#254"
    ("Integration" "#254")
    ("Primitive Mappings" "#257")
    ("Partitions of Unity" "#260")
    ("Change of Variables" "#261")
    ("Differential Forms" "#262")
    ("Simplexes and Chains" "#275")
    ("Stokes' Theorem" "#281")
    ("Closed Forms and Exact Forms" "#284")
    ("Vector Analysis" "#289")
    ("Exercises" "#297")
 )
 ("11 The Lebesgue Theory" "#309"
    ("Set Functions" "#309")
    ("Construction of Lebesgue Measure" "#311")
    ("Measure Spaces" "#319")
    ("Measurable Functions" "#319")
    ("Simple Functions" "#322")
    ("Integration" "#323")
    ("Comparison with Riemann Integral" "#331")
    ("Integration of Complex Functions" "#334")
    ("Functions of Class L^2" "#334")
    ("Exercises" "#341")
 )
 ("Bibliography"
  "#344" )
 ("List of Special Symbols"
  "#346" )
 ("Index"
  "#348" ) )

The name is the first argument, the page number is the second argument, and the rest are optional subsections. Then assuming your outline is saved in a file called outline.txt, run the following to get to add the outline to example.djvu:

djvused -s -e "set-outline outline.txt" example.djvu

Something similar can be achieved with PDF files by using pdftk