Display Math Stuff on HTML export

87 views
Skip to first unread message

Fabian Page

unread,
Jun 21, 2013, 8:44:48 AM6/21/13
to specs2...@googlegroups.com
Hi 

We use the specs2 html output directly as a Documentation. It would be nice if we could also include some Formulas (maybe LaTeX with http://www.mathjax.org?), Graphs (maybe Dot?), or include images. 

As far as i know that is currently not possible? Would it be a good idea to include something like that?

Fabian

etorreborre

unread,
Jun 21, 2013, 9:50:39 PM6/21/13
to specs2...@googlegroups.com
Hi Fabian,

Very good idea! 

Right now the best you can do is to add images with Markdown. I guess that for graphs you can find a way to have your images generated on the side then integrated with a Markdown link.

However for LaTeX and math formulas something like mathjax is certainly the way to go and there's no way to do it with the current HTML exporter. I'll try to give it a go but don't expect anything too soon because I'm also thinking of changing the whole HTML generation to maybe make it template based.

Cheers,

Eric.

Fabian Page

unread,
Jun 24, 2013, 10:35:53 AM6/24/13
to specs2...@googlegroups.com
Hi Eric

If you want i could try to help a little bit, but if you are changing the whole HTML generation then it's probably better if i just wait ;)

FYI:
<script type="text/javascript"
  src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$

You can just load MathJax in the head. And it will search the body for Mathmarkers and convert the stuff in between to a nice Formula. The Problem i see is to have a good Marker for Math ($$ doesn't sound so bad) and it probably has to be protected from the Markdown Parser?

Fabian

etorreborre

unread,
Jun 24, 2013, 7:55:19 PM6/24/13
to specs2...@googlegroups.com
Thanks Fabian for giving me those snippets.

Before I do anything drastic I included an easy way to load your own javascript in the generated HTML.

You simply need to have in the target/specs2-reports directory a file: js/specs2-user.js.

In this file you need an initUserScript function:

function initUserScript(document) {
  var js = document.createElement("script");
  js.type = "text/javascript";
  document.head.appendChild(js);
  MathJax.Hub.Config({
    tex2jax: {inlineMath: [['\\(','\\)']]}
  });
}


Now there need to be some work on the delimiters, especially with interpolated strings. When I use an interpolated string I have to double the delimiters like that:

s2"""

When \\\(a \ne 0\\\), there are two solutions to \\\(ax^2 + bx + c = 0\\\) and they are
$$$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$$$
"""

At least now you have a way to play with it with the latest 2.1-SNAPSHOT.

Cheers,

Eric.

Fabian Page

unread,
Jun 25, 2013, 2:38:58 AM6/25/13
to specs2...@googlegroups.com
Thanks for your update. I will try it out!

Fabian

--
You received this message because you are subscribed to the Google Groups "specs2-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specs2-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Fabian Page

unread,
Jun 25, 2013, 3:02:37 AM6/25/13
to specs2...@googlegroups.com
If i have time i will try out https://github.com/mdaines/viz.js Maybe i can add that with the same mechanism.

You have planned to add the Math Stuff as a Config/Plugin?

Fabian

Am 25.06.2013 um 01:55 schrieb etorreborre <etorr...@gmail.com>:

etorreborre

unread,
Jun 25, 2013, 6:56:22 AM6/25/13
to specs2...@googlegroups.com
> You have planned to add the Math Stuff as a Config/Plugin?

When I have some time I want to see if I can provide the HTML generation as a set of template which are easily modifiable.

But for the time being I suppose that having at least the possibility to inject your javascript should help you integrate useful functionalities.

E.

Fabian Page

unread,
Jun 25, 2013, 7:47:30 AM6/25/13
to specs2...@googlegroups.com
In the moment i'm able to produce "org.pegdown.ParsingTimeoutException". For later i think the math stuff should be cut out before the Markdownparser starts and added again after the parsing. For now is there a way i can increase this Timeout? (I don't get the timeout with a specific line of math but only depending on the amount of text)

Fabian

etorreborre

unread,
Jun 25, 2013, 8:15:43 AM6/25/13
to specs2...@googlegroups.com
> the math stuff should be cut out before the Markdownparser starts and added again after the parsing

That's probably not trivial to do in the present situation.


>  For now is there a way i can increase this Timeout? 

Grab the latest 2.1-SNAPSHOT, I've added the possibility to specify the timeout on the command line:

// set a timeout of 10 seconds 
sbt>test-only *MySpec* -- pegdownTimeout 10000

E.

Fabian Page

unread,
Jun 25, 2013, 8:54:10 AM6/25/13
to specs2...@googlegroups.com
Thanks a lot!

etorreborre

unread,
Feb 24, 2015, 4:55:39 PM2/24/15
to specs2...@googlegroups.com, faeb...@gmail.com
Hi Fabian,

It took a *very* long time but I haven't forgotten you. The upcoming specs2 3.0 has new HTML generation capabilities, based on Markdown parsing with Pandoc which should help with displaying formulas.
The html generation is also template based and you can add/tweak your own template as needed.

The documentation is here (and you can get 3.0-M3 here - html module here).

Would you have time to give it a go and tell me what works/what doesn't?

Thanks,

Eric.
Thanks a lot!

To unsubscribe from this group and stop receiving emails from it, send an email to specs2-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages