Extracting code snippets for LaTeX inclusion
What is THE choice of tool to automate extraction of Rust source snippets for documentation building?
For example, from a certain .rs file I want to extract a certain function, or a data structure - then remove leading spaces, apply highlighting, and then include the snippet in a LaTeX document with a much longer explanatory text and context. Hmm... highlighting may be better done at the LaTeX side - which is the best package for that currently?
I imagine something scriptable like: extractthisfunction perform_computation src/foo/bar.rs >doc/fn_perform_computation.tex
Happy for hints :-)
Posted Sep 27, 2022, 10:14 AM UTC
Short: mdbook and
ANCHORLong:
Get inspiration from the source of the book which is written with use of
mdbook. For selecting snippets isANCHORused.Lines 8...22 from https://github.com/rust-lang/book/blob/main/listings/ch02-guessing-game-tutorial/no-listing-04-looping/src/main.rs
But... this has nothing to do with LaTeX? I use mdbook myself when HTML is good enough. LaTeX is effectively a programming language which lets you produce PDF files with high-quality typography (especially needed for mathematics). Mdbook is great, but it's not the tool to typeset Rust code.