Mathjax \text{} with greek letters inside - jupyter-notebook

I am trying to use mathjax in Jupyter Notebook, and trying to render the following
in Latex typesettings I can render only the followin:
\varepsilon-\text{greedy}(Q)$\
As you can see the dash is very long and adds extra space around dash.
If i move the epsolon within the \text expression the result will be:
\text{\varepsilon-greedy}(Q)$\
\
The dash has no problem bu the epsilon is not rendered.
How can I render the epsilon as intend.
Resolved: UPDATE
Resolved: UPDATE2
That is not the answer for rendering the same outout is just move the dash into the \text
\varepsilon\text{-greedy}(Q)$\

Note that \text{\varepsilon-greedy}(Q) is not valid LaTeX. The \varepsilon macro is a math-mode macro, and is not allowed in text mode, as it appears here, so it would cause an error message in actual LaTeX.
MathJax is designed to process primarily math-mode material, so it does not process macros in text mode, so \varepsilon will be displayed verbatim. If you want to use it in text mode, you could use \text{$\varepsilon$-greedy}(Q) to temporarily enter math mode within text mode.
MathJax version 3 has a textmacros extension that allows processing of some macros in text mode, but that is not available in version 2, which is what is used on StackExchange. (They are using a four-year-old version of MathJax here.)

Related

Different Colored Comments

Simple question about comment code aesthetics (color):
I recently noticed in someone's comment code that part of their comment color changed while using the # symbol. After experimenting with it, I noticed you also need to have an apostrophe (') right after the octothorp (#) as such:
#' #text
^--- This turned orange!
Since I'm a detailed commenter, I'd love to step things up if I could by adding color to my comments. I know part of the reason is my global IDE (RStudio) options, but I'd never seen anything change a comment's color before, so I was just curious:
Why does this occur? I've only seen # used when handling large, more-complex objects that need further specification => Ex. LargeObject#data$variable
Are there other symbols that trigger a color change? There's quotes of course (""), but quotes do not change color when they're commented out with an octothorp (#).
Also, on the image (bottom row), is there possibly a way to start and end a comment, followed by a command, all on one line? => Ex. #comment# print(summary(df))
The special highlighting you're seeing — words being highlighted after #' # — is specific to roxygen markup (a documentation-generation system for R). I don't know why that category doesn't seem to be listed/themeable (see #2).
The RStudio syntax highlighting colours are customizable (you can edit these themes visually), but based on what's documented at the link, there appears to be only one category for "comments".
This question has to do with the R parser, not the RStudio highlighting system. So the answer is "no"; everything from the first # on a line to the line break is considered a comment, no exceptions. In principle you could adjust the RStudio highlighting engine to recognize various delimiters within comments and display material following them differently, but you can't create in-line comments (as you could with /* */ in C) without modifying the R parser.

Render Custom LaTeX Commands within RStudio

Is it possible to have RStudio render custom LaTeX commands in an rmarkdown document within the editor?
That is, I'd like to be able to see my custom commands rendered on-the-fly, without having to knit the document first, in the same way that standard LaTeX is rendered automatically in the editor view.
Yes, though in my experience support is somewhat spotty.
RStudio uses MathJax for LaTeX display. It's not all of LaTeX, it's a subset designed for displaying math mode expressions in a web page. You can read the details here: https://docs.mathjax.org/en/latest/tex.html.
From the "Defining TeX Macros" section of that web page:
You can use the \def, \newcommand, \renewcommand, \newenvironment, \renewenvironment, and \let commands to create your own macros and environments. Unlike actual TeX, however, in order for MathJax to process such definitions, they must be enclosed in math delimiters (since MathJax only processes macros in math-mode).
So if you have something like
$$
\newcommand{\myexp}{\exp}
$$
in your html_document, you can use \myexp later. But this doesn't work in a pdf_document. As I said, spotty.
Generally speaking I wouldn't use Markdown in RStudio for a serious LaTeX document that needs macro definitions. Use knitr's Sweave-like format in TeXworks or TeXShop, and install a processing engine so knitting is supported.

What's an easier way to do tab completion of many superscripts?

I know I can type x\^n and tab to get xⁿ.
But how can I input xᵃ⁺¹ easily, without doing x\^a tab \^+ tab \^1 tab.
I tried using brackets, that doesn't work.
At the moment, there's no shortcut for expanding extended latex superscripts or subscripts via tab expansion. Julia is not actually interpreting the latex you write at tab time – all the symbols are hard-coded in the Julia source as a mapping from simple latex to unicode (you can find them all here). A better approach might be to define some keyboard shortcuts to write unicode sub/superscripts directly.

GNUEmacs/ESS/Latex/Sweave: text displays differently when cursor is in latex code or in R code

When I scroll through an Sweave document (Rnw) with latex and R
code, the text jumps around when the mode changes between Latex and
ESS. The two modes disagree how text should be wrapped. Moreover, I've noticed that when I do
M-x toggle-truncate-lines to enable truncate long lines while the
cursor is within latex code
move the cursor to R code
return to the latex code
the truncated long lines mode is no longer on. Has anyone noticed this? Has anyone solved this problem?
By reading a similar question on the ess-help#r-project.org mailing list, this is what I've learned. When we scroll through the noweb file, we are switching major modes from ESS to LaTeX. Most major modes kill all local variables as part of their initialization, so when we just set the variable locally it's overwritten. To solve this, I modified a hook I found:
(add-hook 'LaTeX-mode-hook '(lambda () (if (string-match "\\.Rnw\\'" buffer-file-name) (setq fill-column 80))))
You could set a similar hook for longlines-mode or toggle-truncate-lines, etc, to meet your needs. The downside to this solution is that you're stuck with a single value for the variable set in the hook.

Mathematica-like (LaTeX) typesetting for own CAS application

As I am using Mathematica a lot I got the idea to write a small and free CAS which just exposes a very small subset of necessary functions and packages to be used and I want to present the results in an appropriate way to the user like Mathematica does (ignore the Facebook logo in the background :D ):
My first idea was to create LaTeX code in the background and to pdflatex the source and include the PDF then in the view... however this seems way to much overkill! I want to write this CAS either in C++ or C# and I want to know if there are any recommended solutions to output nice formula like that.
My first thought was a "real-time formula editing view" but it would be ok to have an input box to enter the commands and formulas and the upper view just to be uneditable output.
A few ways come to my mind.
Use LaTeX behind the scenes to typeset equations, as you say. Again, Cadabra does this.
Use TeXmacs as the front end. Cadabra does this.
Use MathJax. This is a javascript framework which renders TeX equations to images or MathML. It's very easy to use it if you have a HTML view in your UI toolkit. MathJax is used in the sister site MathOverflow, for example.
I find the route 3 is the most attractive.
For calling LaTeX in the background, don't use pdflatex, but use the non-PDF latex to produce a DVI file, and convert it then to PNG with dvipng.
Have a look at the preview package or the standalone class to get the output in the right size (i.e. only the formula, not a whole page).

Resources