Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I've been using Markdown for class notes, and it's great. I even do some preprocessing on the Markdown so I can do things like tables. But this term I'm teaching a class with a lot of math, and I'd love to be able to put LaTeX formulas with Markdown, something like this:
The refinement relation is written $a \sqsubseteq b$, which can be
pronounced "$a$ approximates $b$" or "$b$ is at least as defined as $a$".
I'd like to be able to take each fragment of LaTeX and preprocess it into a nice antialiased PNG file which I could then include in my Markdown via the HTML <img> tag. But I have absolutely no idea how to take a fragment of LaTeX and get a nice image that
Has the right bounding box
Is antialiased
All I know how to do is get full pages in DVI, PostScript, or PDF formats.
I'm sure this problem has been addressed, but I haven't been able to guess the right search terms. Any suggestions how to solve it or where to look for an existing solution?
EDIT: Having installed mathTeX, I can say that the code is inflexible, that it violates the Linux Filesystem Hierarchy standard, and that it is amateur work—in both the good and bad senses of that word. The code is so complex that there are no obvious faults. I will be looking for alternatives.
Also, it's clear that at bottom, solutions are based on dvipng.
ONE YEAR LATER: I never did get the seamless integration I had been hoping for, but I am limping along on a script of my own devising. It turns out that instead of dvipng it is a little easier to use dvips -E and the convert program of ImageMagick. The benefits are slightly more control of things like scaling, and ease of making a transparent background.
The curious can inspect this example.
I can't recommend this solution to anyone. But I can't recommend MathTeX either.
Have you tried with Pandoc?
EDIT:
Although the documentation has become a bit complex, pandoc has supported inline LaTeX and LaTeX templates for 10 years.
Documents like the following one can be written in Markdown:
---
title: Just say hello!
author: My Friend
header-includes: |
\usepackage{tikz,pgfplots}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[CO,CE]{This is fancy}
\fancyfoot[CO,CE]{So is this}
\fancyfoot[LE,RO]{\thepage}
abstract: This is a pandoc test with Markdown + inline LaTeX
---
Just say hello!
===============
This could be a good example or inlined \LaTeX:
\begin{tikzpicture}
\begin{axis}
\addplot[color=red]{exp(x)};
\end{axis}
\end{tikzpicture}
%Here ends the furst plot
\hskip 5pt
%Here begins the 3d plot
\begin{tikzpicture}
\begin{axis}
\addplot3[
surf,
]
{exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}
And now, just a few words to terminate:
> Goodbye folks!
Which can be converted to LaTeX using commands like this: pandoc -s -i Hello.md -o Hello.tex
Following is an image of the converted Hello.md to Hello.pdf file using MiKTeX as LaTeX processor with the command: pandoc -s -i Hello.md -o Hello.pdf
Finally, there are some open source LaTeX templates like this one: https://github.com/Wandmalfarbe/pandoc-latex-template, that can be used for better formatting.
As always, the reader should dig deeper if he has less trivial use cases than presented here.
Perhaps mathJAX is the ticket. It's built on jsMath, a 2004 vintage JavaScript library.
As of 5-Feb-2015 I'd switch to recommend KaTeX - most performant Javascript LaTeX library from Khan Academy.
Add the following code to the top of your Markdown files to get MathJax rendering support
<style TYPE="text/css">
code.has-jax {font: inherit; font-size: 100%; background: inherit; border: inherit;}
</style>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'] // removed 'code' entry
}
});
MathJax.Hub.Queue(function() {
var all = MathJax.Hub.getAllJax(), i;
for(i = 0; i < all.length; i += 1) {
all[i].SourceElement().parentNode.className += ' has-jax';
}
});
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML-full"></script>
and then `$x^2$` or `$$x^2$$` will render as expected :-)
You can always install a local version of MathJax if you don't want to use the online distribution, but you might need to host it through a local webserver.
UPDATE: these days I just use pandoc instead of canonical markdown, but the above is still useful.
I'll answer your question with a counter-question...
What do you think of Org-mode? It's not as pure as Markdown, but it is Markdown-like, and I find it as easy to work with, and it allows embedding of Latex. Cf. http://www.gnu.org/software/emacs/manual/html_node/org/Embedded-LaTeX.html
Postscript
In case you haven't looked at org-mode, it has one great strength as a general purpose "natural markup language" over Markdown, namely its treatment of tables. The source:
| 1 | 0 | 0 |
| -1 | 1 | 0 |
| -1 | -1 | 1 |
represents just what you think it will...
And the Latex is rendered in pieces using tex-mode's preview-latex.
you should look at multimarkdown http://fletcherpenney.net/multimarkdown/
it has support for metadata (headers, keywords, date, author, etc), tables, asciimath, mathml, hell i'm sure you could stick latex math code right in there. it's basically an extension to markdown to add all these other very useful features. It uses XSLT, so you can easily whip up your own LaTeX styles, and have it directly convert. I use it all the time, and I like it a lot.
I wish the markdown would just incorporate multimarkdown. it would be rather nice.
Edit: Multimarkdown will produce html, latex, and a few other formats. html can come with a style sheet of your choice. it will convert into MathML as well, which displays in Firefox and Safari/Chrome, if I remember correctly.
RStudio has a good free IDE that allows for Markdown and LaTeX.
kramdown does exactly what you describe:
https://kramdown.gettalong.org/syntax.html#math-blocks
And it's way more reliable and well-defined than Markdown.
Hey, this might not be the most ideal solution, but it works for me. I ended up creating a Python-Markdown LaTeX extension.
https://github.com/justinvh/Markdown-LaTeX
It adds support for inline math and text expressions using a $math$ and %text% syntax. The extension is a preprocessor that will use latex/dvipng to generate pngs for the respective equations/text and then base64 encode the data to inline the images directly, rather than have external images.
The data is then put in a simple-delimited cache file that encodes the expression to the base64 representation. This limits the number of times latex actually has to be run.
Here is an example:
%Hello, world!% This is regular text, but this: $y = mx + b$ is not.
The output:
$ markdown -x latex test.markdown
<p><img class='latex-inline math-false' alt='Hello, world!' id='Helloworld' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFwAAAAQBAMAAABpWwV8AAAAMFBMVEX///8iIiK6urpUVFTu7u6YmJgQEBDc3NxERESqqqqIiIgyMjJ2dnZmZmbMzMwAAAAbX03YAAAAAXRSTlMAQObYZgAAAVpJREFUKM9jYICDOgb2BwzYAVji8AQg8fb/PZ79u4AMvv0Mrz/gUA6W8F7AmcLAsJuBYT7Y1PcMfLiUgyWYF/B8Z2DYAVReABKrZ2DHpZwdopzrA0nKOeHKj66CKOcKPQJWwJo2NVFhfwCQyymhYwCUYD0avIApgYFh2927/QUcE3gDwMpvMhRCDJzNMIPhKZg7UW8DUOIMg9sCPgGo6e8ZODeAlAP9xLEArNy/IIwhAMx9D3IM+3cgi70BqnxZaNQFkHJWAQbeBrByjgURExaAuc9AyjnB5hjAlEO9ygVXzrplpskEMPchQvkBmGMcGApgjjkAVs7yhyWVAcwFK2f/AlJeAI0m5gMsEK+aMhQ6aDuA1DcDIZirBg7IOwxlB5g2QBJBF8OZVUz95hqfC3hOXWGYrwBSHskwk4EByGXab8QAlOBaGizFKYAtUlgUGEgBTCSpZnDCLQUA+y6MXeYnPDgAAAAASUVORK5CYII='> This is regular text, but this: <img class='latex-inline math-true' alt='y = mx + b' id='ymxb' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFIAAAAOBAMAAABOTlYkAAAAMFBMVEX///9ERETu7u4yMjK6urp2dnZUVFSIiIjMzMwQEBDc3NwiIiJmZmaYmJiqqqoAAADS00rKAAAAAXRSTlMAQObYZgAAAOtJREFUKM9jYCAACsCk4wYGgiABTLInEKuS+QGxKvkVGBj47jBwI8tcffI84e45BoZ7GVcLECo9751iWLeSoRPITBQEggMMDBy9sxj2MDgz8DIE8yCpPMxwjWFBGUMMkpFcbAEMvxjKGLgYxIE8NkHBiYIyQMY+hmoGhi0Mdsi2czawbGCQBTJ+ILvzE0MaA9MHIIWwnWE9A+sBpk8LGDgmMCnAVXJNYPgCJHhRQvUiA/cDXoECZx4DXoSZTBtYgaaEPw5AVnkOGBRc5xTcbsReQrL9+nWwyxbgC88DcJZ+QygDcYD1+QPiFAIAtLA8KPZOGFEAAAAASUVORK5CYII='> is not.</p>
As you can see it is a verbose output, but that really isn't an issue since you're already using Markdown :)
yes, but you'll have to hack it a little yourself. I've written a filter that replaces latex tags $\some\inline\latex$ or $$\some\equation$$ with appropriate image tags to a mimetex.cgi script. It took all of 5 minutes.
Warning: spectacularly ugly...
#!/usr/bin/env python
import sys, markdown,re
MIMETEX_LOC="http://some.server.com/cgi-bin/mimetex.cgi"
def sanitizeLatex(text):
return re.sub(r"\\",r"%5C", text)
def wrapLatexBlock(text):
return '<img alt="equation" class="block" src="%s?%s"></img>'%(MIMETEX_LOC,text)
def wrapLatexInline(text):
return '<img alt="equation" class="inline" src="%s?%s"></img>'%(MIMETEX_LOC,text)
def prepLatexBlock(matchobj):
return wrapLatexBlock(sanitizeLatex(matchobj.group()[2:-2]))
def prepLatexInline(matchobj):
return wrapLatexInline(sanitizeLatex(matchobj.group()[1:-1]))
if __name__ == "__main__":
# initialise markdown
md=markdown.Markdown()
raw_md=open(sys.argv[1],"r").read()
##
# deal with embedded latex
##
raw_md=re.sub(r'\$\$(.*?)\$\$',prepLatexBlock, raw_md)
raw_md=re.sub(r'\$(.*?)\$',prepLatexInline, raw_md)
##
# once latex is parsed, convert md to html
##
main_html=md.convert(raw_md)
# hey presto!
print(main_html)
Of course, you have to define the appropriate css yourself for .block and .inline images...
I came across this discussion only now, so I hope my comment is still useful. I am involved with MathJax and, from how I understand your situation, I think that it would be a good way to solve the problem: you leave your LaTeX code as is, and let MathJax render the mathematics upon viewing.
Is there any reason why you would prefer images?
What language are you using?
If you can use ruby, then maruku can be configured to process maths using various latex->MathML converters. Instiki uses this. It's also possible to extend PHPMarkdown to use itex2MML as well to convert maths. Basically, you insert extra steps in the Markdown engine at the appropriate points.
So with ruby and PHP, this is done. I guess these solutions could also be adapted to other languages - I've gotten the itex2MML extension to produce perl bindings as well.
I was looking for exactly the same thing when I found teqhtml. It does the conversion of $ and $$ equations to images with the nice bonus of aligning the resulting image vertically with the surrounding text. Not a lot of doc but it's quite straightforward.
Hope it helps some future readers.
Sorry to rouse a really old thread, but I've been using jemdoc for a couple of years and it is really excellent.
It is possible to parse Markdown in Lua using the Lunamark code (see its Github repo), meaning that Markdown may be parsed directly by macros in Luatex and supports conversion to many of the formats supported by Pandoc (i.e., the library is well-suited to use in lualatex, context, Metafun, Plain Luatex, and texlua scripts).
The project was started by John MacFarlane, author of Pandoc, and the tool's development tracks that of Pandoc quite closely and is of similar (i.e., excellent) quality.
Khaled Hosny wrote a Context module, providing convenient macro support. Michal's answer to the Is there any package with Markdown support? question gives code providing similar support for Latex.
I have a research project with several files (~100).
The code has been written over the years without any specific style. Each developer (mostly master students that come, code and leave) used their own "style", if any.
Now, I'm trying to maintain the code in a way to make new people that join us follow certain rules. I found that Google published some style-guide. Luckily enough they published also a python script, that is easy to use.
The problem is, the script gives me for each file a tone of silly errors like
Missing space after , [whitespace/comma] [3]
or
Missing space before { [whitespace/braces] [5]
My question is: Is it somehow possible to automatize the correction of such "errors"? That mean running a script over a file that eliminates automatically all those errors.
clang-format might be useful, as it can be run with an option to use Google style rules:
clang-format -style=Google ...
See e.g. http://clang.llvm.org/docs/ClangFormatStyleOptions.html
To update this answer for those of you using vscode, there's an extension there called clang-format and in the settings there is the parameter
Clang-format › Language › Cpp: Style
clang-format fallback style for C++, left empty to use clang-format.style
Typing google in the text box should enable application of the Google formatting rules.
I would like to use R to generates some graphs/plots/charts and then use GTK to display them. One feature is that the plot must be able to auto-update and have some interactive features such as set maxima/minima labels, re-scale, allow for normalisation, etc... The data set is potentially of the order of several thousands data points, possibly up to ten of thousands.
Are there any libraries/modules that already do that? My Google-fu was weak. I do not mind either a c++ or a python one.
If there are no such library, how would I be able to achieve this?
Note: The system is kind of embedded -- it certainly has no Internet connection but does have an internal network. Using the web would increase the cost of the system drastically and thus it is not a good solution to my problem.
As you've put python in your tags too, maybe matplotlib would be of some interest? Just in case.
I wondered whether 10,000 points would be an issue with these graphics devices, and with this gWidgets script running under RGtk2 and Qt it was just about the border of fast enough to be acceptable (certainly on my aging machine 100,000 points was way too many):
library(gWidgets)
options(guiToolkit="RGtk2")
w <- gwindow("test")
pg <- gpanedgroup(cont=w)
fl <- glayout(cont=pg)
gg <- ggraphics(cont=pg)
size(gg) <- c(600, 600)
fl[1,1] <- "No. points"
fl[1,2] <- no_pts <- gedit("10", cont=fl, coerce.with=as.numeric)
fl[2,2] <- gbutton("click me", cont=fl, label="", handler=function(h,...) {
n <- svalue(no_pts)
plot(rnorm(n), rnorm(n))
})
If this speed is acceptable, one can make a GUI along the lines of playwith for your specific needs relatively easily. It might be that the cranvas package can make this faster for Qt.
Otherwise, I don't know if the rgl package of Duncan Murdoch would be useful, but it might be. Simon Urbanek gave a very nice presentation at the last useR meeting where the openGl graphics engine in some browsers allowed for very fast plots with over 1,000,000 points, and this was done over a websocket.
First of all, R at its core does not feature interactive plots -- this goes against the idea of controlling almost everything with the programming language itself.
There are some libraries that allow you to create more or less interactive plots, starting from the simplistic locator function that you would need to wrap into your R programs, and including the manipulate package from RStudio as well as the iplot package. There is even a GTK+ based R package called playwith.
Depending on what you actually want to achieve, maybe using gnuplot would be a better idea.
For a web based solution (web is the future :)) that allows this kind of functionality from a server, I would take a look at the shiny package just released by the people at Rstudio. It looks like what you need, without you having to do any programmng. And you get the bonus that anyone with a browser can open it from anywhere. See this lnks:
http://blog.rstudio.org/2012/11/08/introducing-shiny/
how do we rename .xaml and .cs files?
would like to be able to keep development in synch with the original sketchflow. i.e. sketchflow has features such as the ability to collect client feedback on a per screen basis, etc.
... I kind of answered my own question here, so I'll post it as a follow up. Asked the original question 9 hours ago on the MS site without response... still trying to work out where the best place is to talk to the community, so sorry for the duplicate.
THE ANSWER (IS THERE A BETTER ONE?)
Context: Sketchflow is a prototyping tool. In large teams possibly you want to keep the prototype seperate from the finished version, or there's a large prototyping phase.
My view is that I really like Sketchflow. It's one of the coolest things I've seen for a while (well done Microsoft).
... so for me, I want the prototype to become a the finished product. I want the designers to step in and make transitions whenever they want. I want the designers to kick the process off, and the developers to put in the detail. I'd like our customers to be able to post feedback at any time during the build process. btw: get your developers to check out MVVM. It's very cool.
My bet is that the feedback could get lost if you make a breaking change (a file rename) -- so just beware of that. That wont be a problem for us. We'll get our file names to make sense and then mostly leave it alone. Of course MS could fix this this by creating a globally unique id (Guid) for each screen that is created. Perhaps they've done this already. If someone from MS reads this, please put this on your requested features list.
THE ANSWER:
So here is the answer that works for me:
don't try to hand-edit the xaml / cs, as all the cross referencing that you might be doing with behaviors will break if you aren't really careful. Typical files that need to be modified: .csproj, Sketch.Flow, xxxx.xaml, and xxxx.cs.
To auto do it, download a tool like Ultraedit. Alternatively, you might be able to just use VS 2010 (untested).
Steps with ultraedit:
(BACKUP YOUR PROJECT FIRST)
Search/Replace In Files...
Find in files... "Screen_1_19"
Replace with... "Welcome"
In Files/Types... "."
Directory...
Match Whole Word Only
Hit "Start"
follow the prompts
rename the files (.xaml & .cs) to be Welcome.???? (where ???? is .xaml or .cs) . Since I use SVN, this step gets done for me in one step (no big deal).
If using VS2010 for steps 1 through 8, be careful do longer string replacements first e.g. Screen_1_19 before Screen_1. I think VS treats _ as a word break. On ultraedit you'll be fine.
If there's interest, in the spare time that I don't currently have, I could release a quick tool to do this on codeplex.
** note: because we are working with XML and XML is very particular about being correct, I close expression blend down, and then reopen it again after the replace/rename to see if I was successful + my screen map still has all the flow lines still drawn in.
answer is above in the body of the question.
There're several ways to generate data for tests (not only unit tests), for example, Object Mother, builders, etc. Another useful approach is to write test data as plain text:
product: Main; prices: 145, 255; Expire: 10-Apr-2011; qty: 2; includes: Sub
product: Sub; prices: 145, 255; Expire: 10-Apr-2011; qty: 2
and then parse it into C# objects. This is easy to use in unit tests (because deep inner collections can be written in single line), this is even more convenient to use in FitNesse-like system (because this DSL naturally fits into wiki), and so on.
So I use this and write parser, but it's tedious to write each time. I'm not a big expert in DSL/language parsers, but I think they can help here. What would be the right one to use? I only heard about:
DSL (I mean, any DSL)
Boo (that I think can do DSL)
ANTLR
but I don't even know which one to pick and where to start.
So the question: is it reasonable to use some kind of DSL to generate test data? What would you suggest to do so? Are there any existing cases?
Update: seems like I was not clear enough. It's not about raw string to object convertion. Look at first line and relate it to
var main = Product.New("Main")
.AddPrice(Price.New(145).WithType(PriceType.Main).AndQty(2))
.AddPrice(Price.New(255).WithType(PriceType.Maintenance).AndQty(2))
.Expiration(new DateTime(10, 04, 2011));
var sub = Product
.New("Sub").Parent(main)
.AddPrice(...));
main.AddSubProduct(sub);
products.Add(main);
products.Add(sub);
And note that I first create sub product and then add it to main, even though it is listed in reverse order. Prices are handled in a special way. I want to specify name of Sub product and get reference to it - created. I want to list all product properties - FLAT and NON-REPEATATIVE - on single line. I want to use defaults for properties. And so on.
Update: I'm not convinced to avoid DSL because all the alternative examples are too verbose and not user-friendly. And no-one said anything useful about DSL.
For the data DSL YAML is an excellent candidate. Here is a sample from Wikipedia:
---
receipt: Oz-Ware Purchase Invoice
date: 2007-08-06
customer:
given: Dorothy
family: Gale
items:
- part_no: A4786
descrip: Water Bucket (Filled)
price: 1.47
quantity: 4
- part_no: E1628
descrip: High Heeled "Ruby" Slippers
price: 100.27
quantity: 1
bill-to: &id001
street: |
123 Tornado Alley
Suite 16
city: East Westville
state: KS
ship-to: *id001
specialDelivery: >
Follow the Yellow Brick
Road to the Emerald City.
Pay no attention to the
man behind the curtain.
I used YAML in several projects and happy with it.
However, if we are talking about unit-tests it is usually simpler and more readable to construct necessary objects “by hand” with constructors and property assignments in-place. This is because unit-test are by their nature highly focused on some code (unit), and it shouldn't be hard to create data infrastructure that is just enough for the test. It is OK to operate on half-complete entities in unit-tests, don't bother with constructing data that is not related to this concrete test.
For functional tests YAML is great.
I would first start by seeing if my language of choice was rich enough to build my DSL. C# ought to handle your case quite easily:
Product[] products = new Product[] {
new TestProduct{product="Main", prices=new[]{145, 255}, Expire="10-Apr-2011", qty=2, includes="Sub"},
new TestProduct{product="Sub", prices=new[]{145, 255}, Expire="10-Apr-2011", qty=2}
};
Not quite as pretty, but certainly tolerable enough that I would struggle to justify the extra effort of a custom DSL.
Also note that Expire is initialised with a string, but it is obviously a date. This is perfectly reasonable for a DSL idiom, since TestProduct.Expire's setter can do the translation.
For creating an external DSL I would recommend Eclipse TMF Xtext which is really good (based on ANTLR but simpler), but built on top of Eclipse and Java, however you can generate any code.
When it comes to creating testing data, I was inspired by the way the Ruby on Rails guys do it, which was YAML fixtures as mentioned in another answer, but I also saw an approach using factories, which can help you to get rid of some duplicity and inflexibility. Look at this Railscasts 158: Factories not Fixtures, it might give you some ideas for designing the DSL.