vscode markdown preview not supporting some math commands - visual-studio-code

I'm writing markdown on vscode. But some math latex commands are not supported on vscode built-in preview. E.g.
$$ \ket{\psi} $$
cannot be properly rendered. How do I fix this? How do I add support to a bigger set of commands? Are there any extension that does this for me?
I installed markdown + math extension, but still not working for \ket command. Also for some reason, markdown + math's official example for equation numbers supporting is not working. I don't understand why.

VSCode 1.58 (June 2021) will support math equations rendering in markdown:
Math formula rendering in the Markdown preview
VS Code's built-in Markdown preview can now render math equations using KaTeX
Inline math equations are wrapped in single dollar signs:
Inline math: $x^2$
While you can create a math equation block with double dollar signs:
Math block:
$$
\displaystyle
\left( \sum_{k=1}^n a_k b_k \right)^2
\leq
\left( \sum_{k=1}^n a_k^2 \right)
\left( \sum_{k=1}^n b_k^2 \right)
$$
You can set "markdown.math.enabled": false to disable this feature.
It even comes with:
Markdown math formula syntax highlighting
We now also support highlighting of math equations in Markdown source:
This works both in normal markdown files and in Markdown cells inside notebooks.

Related

VSCode not rendering Markdown with latex in Jupyter notebook

The following Markdown code from a Jupyter notebook produces an error in VSCode. Some initial googling suggests this has to do with Latex rendering in markdown in vscode? Any suggetions on how to fix it, whether it's a VSCode setting, a VSCode extension, or something else? For what it's worth, the equation renders just fine in a browser (i.e., outside of VSCode).
<a name="3.5"></a>
### 3.5 Gradient for regularized logistic regression
In this section, you will implement the gradient for regularized logistic regression.
The gradient of the regularized cost function has two components. The first, $\frac{\partial J(\mathbf{w},b)}{\partial b}$ is a scalar, the other is a vector with the same shape as the parameters $\mathbf{w}$, where the $j^\mathrm{th}$ element is defined as follows:
$$\frac{\partial J(\mathbf{w},b)}{\partial b} = \frac{1}{m} \sum_{i=0}^{m-1} (f_{\mathbf{w},b}(\mathbf{x}^{(i)}) - y^{(i)}) $$
$$\frac{\partial J(\mathbf{w},b)}{\partial w_j} = \left( \frac{1}{m} \sum_{i=0}^{m-1} (f_{\mathbf{w},b}(\mathbf{x}^{(i)}) - y^{(i)}) x_j^{(i)} \right) + \frac{\lambda}{m} w_j \quad\, \mbox{for $j=0...(n-1)$}$$
I could reproduce your error...\mbox{} seems to be problematic.
Under the assumption, that you are using \mbox for the correct spacing, there is a simple alternative to fix it. \, creates a half space width...
The following code should do the trick:
In this section, you will implement the gradient for regularized logistic regression.
The gradient of the regularized cost function has two components. The first, $\frac{\partial J(\mathbf{w},b)}{\partial b}$ is a scalar, the other is a vector with the same shape as the parameters $\mathbf{w}$, where the $j^\mathrm{th}$ element is defined as follows:
$$\frac{\partial J(\mathbf{w},b)}{\partial b} = \frac{1}{m} \sum_{i=0}^{m-1} (f_{\mathbf{w},b}(\mathbf{x}^{(i)}) - y^{(i)}) $$
$$\frac{\partial J(\mathbf{w},b)}{\partial w_j} = \left( \frac{1}{m} \sum_{i=0}^{m-1} (f_{\mathbf{w},b}(\mathbf{x}^{(i)}) - y^{(i)}) x_j^{(i)} \right) + \frac{\lambda}{m} w_j \quad\, for\,\,j=0...(n-1)$$
for\,\,j=0...(n-1)
With the result...
Hope this fix helps. I am still looking for an explaination though

Why can't I show the ð symbol in LaTeX?

I can use \DeclareUnicodeCharacter{0278}{\phi} and then $ɸ$ to display the ɸ symbol in LaTeX. However, when I try to use:
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{0360}{\eth}
\begin{document}
$ð$
\end{document}
ð doesn't display. Why doesn't this work?
You need
a package which provides the \eth macro in the encoding you are using, e.g. stix
the \eth macro from this package is, unlike \phi, a text macro and not a math macro, so either use it outside of a math environment or surround it with \text{..} from the amsmath package
if your tex distribution is not totally out of date, you don't need \usepackage[utf8]{inputenc}, that's the default since a couple of years
\documentclass{article}
\usepackage{amsmath}
\usepackage{stix}
\DeclareUnicodeCharacter{0360}{\eth}
\begin{document}
ð
$\text{ð}$
\end{document}
or avoid all the trouble and simply use an unicode aware engine like lualatex:
% !TeX TS-program = lualatex
\documentclass{article}
\begin{document}
ð
\end{document}

Why using _LatexSmallFractionConstant:=1 causes bad latex to be generated?

The option _LatexSmallFractionConstant:=1 is very useful in Maple, as it makes the fraction generated in latex looks natural. Here is an example
restart;
latex(1/2);
1/2
Now using _LatexSmallFractionConstant:=1, the output becomes
restart;
_LatexSmallFractionConstant:=1:
latex(1/2);
{\frac{1}{2}}
Which is the correct Latex.
But _LatexSmallFractionConstant:=1 causes big problem in other places, like here
mu:=1/((4*t+1)^(8/5)*(t-1)^(7/5));
Now see what happens when latex is generated with _LatexSmallFractionConstant:=1 set
_LatexSmallFractionConstant:=1:
latex(simplify(mu))
{1 \left( 4\,t+1 \right) ^{-{\frac{8}{5}}} \left( t-1 \right) ^{-{
\frac{7}{5}}}}
Which is completely wrong. It renders as
Removing _LatexSmallFractionConstant:=1: gives
restart;
mu:=1/((4*t+1)^(8/5)*(t-1)^(7/5));
latex(simplify(mu))
{\frac {1}{ \left( 4\,t+1 \right) ^{8/5} \left( t-1 \right) ^{7/5}}}
Which renders correctly.
Is there a way to correct the above, so I can still use _LatexSmallFractionConstant:=1: ? I need to use this option to make fractions appear in correct Latex, but I also do not want to obtain bad Latex in other places like the above.
Is there a solution to this problem?
Maple 2018.1 on windows.
It's a bug. You should report it. I'd link to where, but at the moment, it looks like both www.maplesoft.com and www.mapleprimes.com are down.

How does matlab's latex interpreter handle unicode?

I'm wondering how MATLABs latex interpreter for plot text deals with unicode characters? It is weirdly inconsistent. Which, y'know, invalidates the whole ENTIRE point of unicode.
TOY CODE
%*** Setup some text for a plot title
Title_Txt{1} = [char(8734) ,' SNR~~~' , char(10) , '(-)'];
Title_Txt{2} = ['50 SNR~~~' , char(10) , '(-)'];
%*** Plots!
x= 1:1:10
y= rand(size(x))
figure(1)
subplot(211)
plot(x,y)
title(Title_Txt{1} , 'interpreter' , 'latex')
subplot(212)
plot(x,y)
title(Title_Txt{2} , 'interpreter' , 'latex')
Toy code demonstrates that the latex interpreter handles char(10) --- a new line. But it breaks from char(8734) --- the infinity symbol.
Obviously I can work around this by feeding in a latex symbol that matlab knows (another source of frustration but that's for a different discussion), but I am curious about
what MATLAB is doing under the hood here?
is there is a fix for getting unicode into latex?
I suspect the (unsatisfying) answer here is that the Latex interpreter portion of Matlab does whatever the included version of Latex does, and Latex in general doesn't support Unicode. (For Latex solutions, see: https://tex.stackexchange.com/questions/34604/entering-unicode-characters-in-latex. Of course this doesn't help Matlab users.)
As to why Latex doesn't support Unicode. I'll note that the first copyright date on my Latex users' guide is 1985, and the latest release is version 2e, from 1994. Unicode was not really mainstream until the '90's.
(This is a poor answer, but became too long for a comment.)

Surface plot with LaTeX code in label

I would like to use the Letter μ (LaTeX: \mu) in my surface plot. Unfortunately when I use the LaTeX symbol \mu in the zlabel('Power [\muW]'); command it results in:
'Power [ μ W]' instead of 'Power [μW]'
How can I avoid these spaces around μ?
I can't reproduce your problem, which could be due to you using an older version of Matlab. In the past it was neccesary to set the latex interpreter fist, before using Latex syntax. So the following should work:
zlabel('Power [$$\mu$$W]','interpreter','latex');
Nowadays it seems to recognize automatically at least greek letters.