4
$\begingroup$

I am calling Wolfram Alpha using WolframScript. That is, I can't display all the beauty that is inserted into Wolfram Mathematica Notebook. Let's say I execute a line like this:

result = WolframAlpha["Weather in Saratov", "PodInformation"]; 

There are tables in the results. For example this one:

table = {{"WeatherStationInformation:WeatherData",1}, "Content"} /. result

enter image description here

If I look at the full form of this table, I see that it is a cumbersome expression that is only handled properly in the Mathematica UI, since it consists of Boxes. My question is if there is an easy way to convert the results from Wolfram Alpha to a more primitive form, given that it was a table/text/list/group of elements/graph/picture/ picture

  • picture ->
  • table -> |cl1|col2|...
  • list -> * item1
  • ...
$\endgroup$

2 Answers 2

6
$\begingroup$

An easiest way is to make use:

  1. Pod ComputableData - see how HERE
  2. MathJax in markdown

So getting the data from

podDATA=WolframAlpha["Weather in Saratov",
    {{"WeatherStationInformation:WeatherData",1},"ComputableData"},
    PodStates->{"WeatherStationInformation:WeatherData__Show metric"}];

you then use TeXForm:

Grid[podDATA,Alignment->Left]//TeXForm

to get literally the result below working in markdown:

$$\begin{array}{ll} \text{name} & \text{UWPP} \\ \text{relative position} & \text{186 km NNW} \\ \text{relative elevation} & 41\text{m} \\ \text{local time} & \text{11:07:03 am UTC+04 $|$ Thursday, February 8, 2024} \\ \text{local sunlight} & \{\text{sun is above the horizon},\{\text{azimuth: 149${}^{\circ}$ (SSE)},\text{altitude: 18${}^{\circ}$ ()}\}\} \\ \end{array}$$

Right-click on the above table and you will see that it is not an image but MathJax. I used this code in this post editor and this is the output of TeXForm besides $$...$$:

$$\begin{array}{ll}
 \text{name} & \text{UWPP} \\
 \text{relative position} & \text{186 km NNW} \\
 \text{relative elevation} & 41\text{m} \\
 \text{local time} & \text{11:07:03 am UTC+04  $|$  Thursday, February 8, 2024} \\
 \text{local sunlight} & \{\text{sun is above the horizon},\{\text{azimuth: 149${}^{\circ}$  (SSE)},\text{altitude:
   18${}^{\circ}$  ()}\}\} \\
\end{array}$$

Perhaps not super ideal. After some effort you could write parser to get the format of true markdown table:

Or there are tools that do it for you if you search for: tex to markdown converter.

$\endgroup$
4
$\begingroup$
  1. convert to Latex
  2. save to file, say A.tex
  3. use pandoc -s A.tex -o A.md to convert to markedown
  4. test using online tool gives

enter image description here

result = WolframAlpha["Weather in Saratov", "PodInformation"];
mma = {{"WeatherStationInformation:WeatherData", 1}, "Content"} /.   result
TeXForm[mma]

Mathematica graphics

The Latex is

\begin{array}{ll}
 \text{name} & \text{UWPP} \\
 \text{relative position} & 116\thickspace \text{mi} \text{NNW}\text{  }(\text{from }\text{center of Saratov}) \\
 \text{relative elevation} & 135 \text{feet} (\text{above} \text{center of Saratov}) \\
 \text{local time} & 11:10:59 \text{am} \text{UTC+04}\text{  $|$  }\text{Thursday, February 8, 2024} \\
 \text{local sunlight} & 
\begin{array}{l}
 \text{sun}\text{ is}\text{ above the horizon} \\
 \text{azimuth: }150{}^{\circ}\text{  }(\text{SSE})\text{  $|$  }\text{altitude: }18{}^{\circ}\text{  }() \\
\end{array}
 \\
\end{array}

Copy the above to plain textfile, say A.tex, Make sure to add $$ and close everything with $$.

Use Latex to markdown converter. see latex-to-markdown-converter

pandoc -s A.tex -o A.md

Test A.md using any markdown editor such as https://dillinger.io/ but there are others.

enter image description here

but notice that some styling is lost. Such as frames and such.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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