ddoc latex/formulas?

Johan Engelen via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 15 07:37:04 PDT 2016


On Thursday, 15 September 2016 at 11:39:13 UTC, Andrei 
Alexandrescu wrote:
>
> * ddoc has absolutely nada notion of rendering. To ask "how do 
> I render sqrt and aligned matrices with ddoc" does not compute. 
> Is there agreement on that?

D has absolutely no notion of "databases", but I think it's fair 
to ask "how do I retrieve data from a database using D".
DDoc bare does not need a notion of rendering, but the base 
system in place (call it the DDoc std lib) does need to present a 
way for a user to end up with a math equation "rendered" well.

>> A great addition to DDoc would be to allow LaTeX bits, like 
>> doxygen
>> does, and render it nicely for both web and PDF output. You 
>> just mark a
>> piece of text as <LatexStartsHere>....<LatexOut>.
>
> We already have that. Just use latex syntax inside \( \) and 
> import mathjax if you want to generate HTML, or do nothing else 
> to generate LaTeX.

Well, I'm pretty sure just typing \( \) and running `dmd -D` is 
not going to give me the output that I want. Indeed it doesn't.

But, as you write, it's easy to make it happen. Full example:
```
/**
* Macros:
* DDOC =
* <!DOCTYPE html>
* <html lang="en-US">
* <head>
* <script type="text/javascript" async 
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
* </script>
* <title>$(TITLE)</title>
* </head>
* <body><h1>$(TITLE)</h1>$(BODY)</body>
* </html>
*/

/**
* \[
*  \mathbf{V}_1 \times \mathbf{V}_2 =
*   \begin{vmatrix}
*    \mathbf{i} & \mathbf{j} & \mathbf{k} \\
*    \frac{\partial X}{\partial u} & \frac{\partial Y}{\partial 
u} & 0 \\
*    \frac{\partial X}{\partial v} & \frac{\partial Y}{\partial 
v} & 0 \\
*   \end{vmatrix}
* \]
*/

module ddoctest;
```

`dmd ddoctest.d -D -o-` produces an HTML file with nice looking 
math in it.

Now, can we please add this question to stackoverflow, and add 
this as an answer?
:)






More information about the Digitalmars-d mailing list