lbeckman314 / mdbook-latex

An mdbook backend for generating LaTeX and PDF documents.
https://liambeckman.com/code/mdbook-latex/
Mozilla Public License 2.0
104 stars 12 forks source link

Suggestions: md2tex and mdbook-latex #12

Open enaut opened 4 years ago

enaut commented 4 years ago

Hey,

I've selected this as my rustlearn project - I do know several other programming languages, some quite proficient. I was toying around with this project and copying things into my own project and so on.

Things that I think should be conceptually different:

As you cannot AFAIK create a Parser from Events and the Parser is more or less just an Iterator. I'd suggest to change the function signatures so that there is a function that takes an Iterator of events and generates the tex code. That way you can still give it a parser, but also a Vec or something similar I moved the parser-creation to a sepparate function for backwards-compatibility (pullrequest: lbeckman314/md2tex/pull/4):

/// Converts markdown string to tex string. (But I'd not use this function in mdbook-latex)
pub fn markdown_to_tex(markdown: String) -> String {
    let mut options = Options::all();

    let parser = Parser::new_ext(&markdown, options);

    return parser_to_tex(parser); // optionally this could add a very simple header and footer so that the resulting .tex does compile.
}

/// Takes a pulldown_cmark::Parser or any iterator containing `pulldown_cmark::Event` and transforms it to a string
pub fn parser_to_tex<'a, P>(parser: P, headingoffset: u32) -> String
where
    P: 'a + Iterator<Item = Event<'a>>,
{
    [...]

With these changes I think md2tex would be way more flexible and mdbook-latex would be better at correctness and extendability.

I'm going to do some of it anyways to learn rust - should I send pullrequests? If so do you agree with the changes above? what are your 2¢? - what do you want pullrequests for?