2

I'm going to write an article. It will have math equations, images, and tables. My article frequently contains repeated content with slight modifications. For instance my article may have

If the legs of a right triangle are 3 and 4, then the hypotenuse is 5.

If the legs of a right triangle are 3 and 5, then the hypotenuse is 5.83.

If the legs of a right triangle are 3 and 6, then the hypotenuse is 6.71.

If the legs of a right triangle are 3 and 7, then the hypotenuse is 7.62.

If the legs of a right triangle are 3 and 8, then the hypotenuse is 8.54.

I must publish it in my web blog so that everyone can access it easily. In addition, I must print out my article in hard copy.

If I write in HTML, then print to pdf?

I'm proficient in HTML with CSS and JavaScript. I can use mathjax to typeset math equations. Creating tables in HTML is much easier than in Latex. Including images in HTML doesn't have to worry about spaces in image file name. (See How to include graphics with spaces in their path?).

I will use JavaScript, specifically VueJS, a powerful template and calculation engine to generate the repeated paragraphs.

<!-- language: html -->

<div v-for="x in range(4,8)">
    <RightTriangle leg1="3" v-bind:leg2="x"/>
</div>

VueJS will automatically generate the 5 paragraphs, looping x from 4 to 8, and calculate the value of hypotenuse.

If I take this approach that write the article in HTML/CSS/JavaScript, then print it to hard copy, the images and the tables don't float properly as they are in latex. If there is no enough space holding an image, the image is pushed down to the next page, while leaving blank spaces on the previous page. I don't like that.

If I write in Latex?

I didn't learn Latex programming or calculation. I feel calculating Exponential and square root in Latex is not as easy as in JavaScript. I don't know if it's easy to use a for-loop to generate the 5 paragraphs.

Not to mention more complicated logic, eg. array indexing, which I think is easy to express in JavaScript than in Latex.

Even if I wrote out the article in Latex, I may use latex2html or pandoc to convert it to HTML. I'm not sure the quality of the result especially if I use latex for-loop or calculation syntax.

Question

Can I write once, and publish to HTML and PDF(hard copy), with Latex floating support, Latex Equation support, and automatic content generation with possible complicated logic?

  • 2
    You may be interested in ConTeXt rather than LaTeX as it has XML processing capabilities (HTML to XML should be trivial for you) and has the mechanisms that you want. Apart from PDF you can even create EPUB files. – TeXnician Nov 3 '19 at 22:20
  • 1
    Pandoc? Write markdown, convert to LaTeX, HTML, and docx. – Oleg Lobachev Nov 3 '19 at 22:43
  • tex4ht can be used for converting from LaTeX to the format suitable for static site generators. see tex.stackexchange.com/a/506587/2891 for example. – michal.h21 Nov 3 '19 at 22:45
  • 1
    The source code for Nicola Talbot's book does four versions: dickimaw-books.com/latex/novices/index.html Might be worthwhile looking at. Format commands are easy enough to translate (or emulate), but programming logic (the language) of class modules and sty files would require a combination of python/perl/javascript (maybe java, too) to "translate" the functions and looping, implicit and explicit (including the macro expansion at the core, and token processing): in effect building your own tex compiler - I would use XML for that. Or use lua/expl3 and run parallel threads. – Cicada Nov 4 '19 at 10:27
1

Yes, you probably can.

But why have such a headache?

LaTeX may have a command like \section to start a section, but there is no marker for the end of the section. TeX4ht is really good in overcoming such restrictions, but maybe you try yourself with an example *.tex file that suits your needs.

There are -- mainly -- to other ways: pandoc or orgmode.

orgmode comes with a feature called babel: you can run arbitrary code in your *.org file (list of languages here) and get the result back in the org file. There as well is an export function to LaTeX which works quite well. And orgmode has the advantage to run inside Emacs, so you have an excellent editor as well! :-))

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.