I know of the cprintf Undocumented Matlab way of changing the color and other font properties in the command window but I also saw this symbols in plots. This shows that Matlab supports TeX markup in plots at least. I played with it for a while and found it very useful. So much so that I wanted to find a way to include this in the command window.
I first tried sprintf('\color{red} Something\n') and was rewarded with an error that \c is not a recognized escape sequence. Google was no help either.
This is a way to use the some of the other formatting options in the command window?
The command window doesn't support TeX. Sorry. The TeX support is part of the routines that generate the figures, not the code that displays the command window.
In essence, the command window is, by modern standards, a pretty boring terminal emulator. There's not much you can do with it.
If you're looking for something to do math in that generates fancy notebooks on the fly that combine the commands you type and their results in a nice-to-read, modern way, you might just want to avoid Matlab and have a look at Jupyter (formerly IPython) Notebooks, which of course support MathJax (and thus, LaTeX math syntax): https://try.jupyter.org/
Related
I have already seen some other links related to this question, which are mentioned as below:
How to write LaTeX in IPython Notebook?
https://towardsdatascience.com/write-markdown-latex-in-the-jupyter-notebook-10985edb91fd
https://colab.research.google.com/drive/18_2yFdH8G-6NXY_7fTcshMoScgJ-SYac#scrollTo=go3imAWqE9au
However, I am still facing some problems while using the Latex code inside Jupyter notebook.
For example,
\begin{align*}
f(x) &= x^2\\
g(x) &= \frac{1}{x}\\
F(x) &= \int^a_b \frac{1}{3}x^3
\end{align*}
This works fine as Markdown but
\begin{equation*}
f(x) &= x^2\\
g(x) &= \frac{1}{x}\\
F(x) &= \int^a_b \frac{1}{3}x^3
\end{equation*}
does not.
While trying to create an ordered list using the following
\begin{enumerate}
\item The labels consists of sequential numbers.
\item The numbers starts at 1 with every call to the enumerate environment.
\end{enumerate}
However, $\textbf{This is a bold text.}$ works.
It's really confusing what I can use and whatnot. Is there any way so that I can use only Latex code (and no HTML or other code) inside Visual Studio code to format my texts and equations without worrying about which will work and which not?
The short and very pragmatic answer is: you can't.
When you type something like $ a^2 $ in a markdown cell, what Jupyter Notebook actually does is send it to a library called MathJax. Mathjax, in its turn, does not compile the TeX code you typed using a standard LaTeX compiler. It, instead, just looks for mathematics environments and try to process the TeX-like syntax into something MathJax can understand.
Diving in LaTeX-stuff
There are two modes in (La)TeX: the text mode and the math mode, which are treated separately by the TeX compiler. For example, open your TeX editor and try to compile the following code.
\documentclass{article}
\begin{document}
a^2
$ ação $
\end{document}
You'll receive that error:
! Missing $ inserted.
<inserted text>
$
l.4
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
Missing character: There is no ç (U+00E7) in font cmmi10!
Missing character: There is no ç (U+00E7) in font cmmi10!
Missing character: There is no ã (U+00E3) in font cmmi10!
Missing character: There is no ã (U+00E3) in font cmmi10!
It's telling you that (1) you can't use ^ in text mode; (2) you can't use unicode characters such as ç and ã in math mode.
At this point, it's important to remember that align environments are courtesy of amsmath or mathtools packages, and doesn't exists in "plain" LaTeX
Back to MathJax
Unlike a real LaTeX compiler, MathJax does not implement the entire TeX macros universe, but only those related to the math mode (as the name suggests). From documentation:
Note that the TeX input processor implements only the math-mode macros of TeX and LaTeX, not the text-mode macros. MathJax expects that you will use standard HTML tags to handle formatting the text of your page; it only handles the mathematics. So, for example, MathJax does not implement \emph or \begin{enumerate}...\end{enumerate} or other text-mode macros or environments. You must use HTML to handle such formatting tasks. If you need a LaTeX-to-HTML converter, you should consider other options.
However, there are some exceptions. The default configuration of TeX input processor allow detecting environments outside math mode, so those environment related to math (equation, align, matrix, etc) can be correctly typeset. Recall that LaTeX does not implements align out-of-the-box, while MathJax does.
And what about the buggy equation environment?
Regarding your buggy equation environment, it's more a LaTeX stuff. equation environments does not support line breaks (\\) neither & (the first one I can't explain exactly why, but certainly someone in TeX SE can), so your input is invalid.
You can now with the latest version of VS Code. The feature is still in preview (as of writing) so you have to enable it in settings.json by adding "notebook.experimental.useMarkdownRenderer": true
Restart VS Code and try $$y=x^2$$ and press ctrl+enter to see it rendered. I think for now the equation needs to be on a separate line by itself.
Here's the announcement: https://code.visualstudio.com/updates/v1_55#_preview-features
As in Julia REPL, we can type in latex styled variables by using tab and \epsilon to get the greek letter and give it a value. Since I mainly wirte Julia
codes in VS Code now, I was wondering if we could do that in vs code also? or can we do that in Jupyter notebook?
and in advance, can we have complicate latex styled computation formula in vs code when progrmming with the julia extension? or in Jupyter notebook
What I want to describe here is something very similar to what Mathematica can do, which makes the math equations much easier to read.
There is a VS Code Julia extension, which does support LaTeX-like tab completion, just like in the REPL. It should also just work in Jupyter, if you have the correct Julia kernel installed. You can find out more about that here.
In terms of a Mathematica style notebook workflow, Jupyter is probably the closest. Julia code still has to be regular Unicode text, so you can't expect your code to look exactly like free-form LaTeX, but you might want to look at Latexify.jl, which can convert Julia expressions and data structure into nice-looking LaTeX code. If you output LaTeX code generated by Latexify.jl in a Jupyter cell, it should even render correctly using MathJax. Otherwise, you can also just write LaTeX formulas inside Markdown cells with Jupyter.
This is really a two part question, but they are in the same vein, so I will ask in one post.
When I flip through various colors, I see that they also have the ability to change the color of the Output window. Which VS Code setting can I use to change the color of this output? To be specific, I am not asking about the terminal, I am inquiring about the output window that displays the output when using coderunner as an example. Please refer to the screenshot to see which window I am referring to.
Second question is I can see that the output does support multiple colors. I am trying to use the module cpprint from the python lib prettyprinter to print colored output to this window. When I run the script in a terminal, I am getting colors, but in the output window, I am not getting any colors. Will it be possible for me to get similar colored output in the output window as in the terminal? I am assuming the output window supports colors because the [Running]... and end are in colors.
The Python lib I was referring to
Thanks!
So, for long while now, we have had to resort to an IBM developed extension named Output Colorizer, however, this extension clashed with other extensions, and cuased an array of bugs/issues. I personally had to disable it because it was causing text to not print at all in my output window.
We now have a much more robust, built-in solution, and it doesn't require doing anything.
Visual Studio Code added syntax-highlighting support to the "Output Channel" as part of a Milestone that it had been working on, in its March 2022 Release.
The syntax highlighting is configured by a specified languages grammar.
The language grammar that is used will vary, depending on which output channel you use. The person who decided on the language syntax highlighting used for any given output-channel is the person who authored the extension that the output-channel belongs too.
Here is the link to the official release note
Because the output highlights syntax on a language basis, configuring what colors the new feature uses to color any given text, is done the same way you color syntax.
In Depth Explanation:
If numbers are set by your theme to render green (#00FF00), then, then numbers that are printed in the Output View Panel will also be green.
If the language defined constants true & false render as a pastel-red (#FF7799) when you are writing TypeScript, but when you have a Java file open, they render as a bright pastel-yellow-green (#BBEE88), then the way they render will be contingent on whether or not the output window was set to Java or TypeScript. Obviously an output window for an extension that's a tool for Java, will most likely highlight syntax as Java. A typescript-tool extension will likely highlight all syntax as if it were typescript.
Some People Might Prefer that the Feature be more Customizable
Some people might want a more customizable feature, but I think it would be a mistake, even if it were possible, to highlight the syntax in the output differently from the editor. In fact, thinking about it, it would be stupid to have done that. It makes perfect sense that it is the way it is.
Anyways, that is the end of the Color in the Output Channel, or at-least for now.
I'd like to use emacs in some kind of batch mode to just render a file with syntax highlighting and exit. Specifically, I want to dump the fontified buffer with ANSI escape codes so that it shows up reasonably syntax-highlighted on my terminal. Is there any way to do this?
The ansi-lpr.el library seems to be kind of along the lines of what I want, but the output isn't colorified. I can't figure out how to get over that final hurdle — there are a lot of modules to digest ANSI escape codes into Emacs text properties (e.g. ansi-color.el) but I haven't found anything that does the reverse. If anyone can point me to something that does, I think I can piece together the rest.
Alternatively, I've seen some hacky approaches like this answer (using script and capturing the output) but in my experiments that approach has seemed unlikely to be fruitful — you get tons of undesirable control sequences mixed in with the highlighted text.
The overarching motivation here is to use emacs in a $LESSOPEN pipe to get syntax highlighting when I page files. In case you're going to say it, I've tried and "just page files in Emacs" is not acceptable for me.
I'm glad to announce a new package, e2ansi, that (hopefully) does what you asked for.
The package provides a command-line tool e2ansi-cat that starts Emacs in batch mode, opens files, syntax highlight them (using font-lock), and creates ANSI-colored versions of the syntax highlighted files.
You can integrate this into less by setting the following variables to, for example:
export "LESSOPEN=|emacs --batch -Q -l ~/.emacs -l bin/e2ansi-cat %s"
export "LESS=-R"
export MORE=$LESS
The end result looks like the following:
You can vary the colors and attributes like bold, underline, and
italics by using a suitable Emacs theme.
The e2ansi package is located at https://github.com/Lindydancer/e2ansi
Personal note
I would like to thank you for posting this question, it directly inspired me to write e2ansi.
I have found a code to make typing equations in LaTeX in a simpler and faster way. Instead of typing
\begin{equation}
\end{equation}
I can now type
\be
\ee
It works great and I am happy with it. The code, found in this document (p. 13), is
\makeatletter
\newcommand{\be}{\begingroup
\setlength{\arraycolsep}{2pt}
\eqnarray%
\#ifstar{\nonumber}{}%
}
\newcommand{\ee}{\endeqnarray\endgroup}
\makeatother
My problem is that I use emacs, and it doesn't recognise those math delimiters and hence it doesn't give the face the proper math colour. I have tried to customise this by using the command M-x customize-apropos to try and find something I could use, but the closest I got were the variables
'font-latex-math-environments',
which I don't think is what I am
after since from what I can see I
can only type the name of the
command which goes inside the curly
brackets in \begin{} and \end{}
'font-latex-make-built-in-keywords',
which would require more knowledge
from me than I have, and I don't
even know whether it would work.
What I would like to know, thus, is how to set up Emacs so that whenever I used the pair \be and \ee it would give the face the same colour as I set up for math. I imagine this would require an emacs lisp code, which would be great so I could modify it to include other things if so I wished.
Can anyone help me getting this done?
This is not really an answer to your question, but if it's just about saving keystrokes for writing an equation environment, you might want to try the following.
From the tags under your question, I assume you're using AUCTeX mode. With that, instead of typing
\begin{equation}
\end{equation}
every time, use the following shortcut to have AUCTeX insert an environment interactively: C-c C-e. This will prompt your for the name of the environment ("equation") which you can type using tab-completion.
So you do save a couple of keystrokes, the result is syntactically correct, you don't need the additional \be and \ee commands, and what's best is that this approach is generic, i.e., it works for all LaTeX environments, not just equation.