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.
Related
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.)
Recently I have seen Julia code like this with special characters:
How can I write Julia code like this? Do I need to have a special editor or can I do this also with e.g. Notepad++?
Julia allows you to use various Unicode symbols for variable and function names, and it makes sense in a lot of the scientific domains Julia is used in, making the code be more alike the scientific notation. (It's sometimes called "executable math" for this reason, though at this point it's more like "executable scientific notation".)
However, in any new code you write, it's not generally necessary to use these symbols, and you can write the code with the basic ASCII characters. Julia language and its standard libraries always provide ASCII equivalents for the Unicode functions they use.
For eg., ⊻ is the XOR character, and you can write 2 ⊻ 11 to get the XOR of the two numbers. But you can also instead write xor(2, 11) to get the same result, and they're exactly equivalent to the language. It's considered good practice for external packages as well, to provide their interface in terms of ASCII-typable names to the extent possible, even if internally Unicode-only names are used.
With that said, if you find you do need to work with code that uses such Unicode symbols, there are a few options:
Option 1: Autohotkey-script for converting LaTeX-like input to unicode characters.
Usually, the way to enter these character in Julia is using LaTeX-like syntax, for eg. \epsilon for ϵ. The AutoHotKey script provided here gives somewhat similar functionality, allowing you to type LaTeX-like input and converting it automatically into the corresponding symbols.
Option 2: A copy-paste list of symbols
This is pretty ad-hoc, but can work for situations where you just need to edit some existing code. You can use a clipboard manager like ClipX, or Win10's inbuilt one, to keep a copy of all the symbols the script uses. At any point, you can choose and insert the particular symbol you need.
Option 2a: Copy-paste from the REPL/Jupyter/Pluto
I'll put this option too here since it uses the clipboard as well. This makes use of the usual workflow for writing Julia code - you'll probably want to try out the code in the REPL or in a notebook anyway, so you can use the tab-completion features there, and then copy that code into your editor. Julia has a clipboard function too, so after trying out median(sin.(-ℯ:0.01:π)) in the REPL, you can surround that in triple quotes and pass it to clipboard like this: """median(sin.(-ℯ:0.01:π))""" |> clipbaord from the REPL itself.
Option 3: Use JuliaEditorSupport/julia-NotepadPlusPlus
This is sort of the "official" option, but only the syntax highlighting file has been updated recently, and the quality and reliability of the Autohotkey script here isn't clear. I'd be hesitant to recommend this option.
Option 4: Use a better supported editor
It's hard to let go of familiar tools, but in this case, this is probably the most reliable option long term. Julia for VSCode is probably the best supported editor right now, but the plugins for Vim and Emacs are also pretty good. If VS Code is too heavy (and Vim and Emacs unfamiliar), you can also try the plugin for Sublime Text which should be both easy to use and light.
Does the RStudio text editor have a simple automated way to convert this:
c(
"097",
"085",
"041",
"055"
)
to this: c("097", "085", "041", "055")?
There are answers for other text editors (e.g., here), but I'm looking for a solution specific to RStudio.
Not an automated solution per se, but many people don't know about RStudio's support for multiline cursors. Just hold Alt (Option on Mac) and drag across multiple lines, then press backspace a few times:
Also very handy for adding commas or closing parentheses to multiple lines at once.
The multi-line cursor answer from #jdobres is how I'd do it, but you should also be aware of the excellent datapasta package, which can do what you're asking and a whole lot more. A very helpful add-in for RStudio, imo.
As mentioned by #rdelrossi, datapasta is a helpful package for editing and styling text/code. On Mac, once you install the package (also installs as an add-in), then you have access to several keyboard shortcuts. For example, to convert a vector from vertical to horizontal, you could use vector_paste() or use the keyboard shortcut, which is ctrl+alt+shift+v.
You can read about some of the other functions and shortcuts (e.g., paste as vertical vector) at Typical Datapasta Usage with Rstudio.
RStudio has a find/replace feature. You can replace new line characters \n with spaces for this effect. Make sure you have the "regex" box checked for it to work.
You can use dput:
dput(c(
"097",
"085",
"041",
"055"
))
#> c("097", "085", "041", "055")
It is also possible to set-up a code formatting add-in that you can bind to keyboard shortcuts by installing the styler package.
I have been using WxMaxima for my symbolic calculations for a while now. The good thing about WxMaxima is that you can get formatted outputs right in the program and then export them to LaTeX format with a click of the mouse.
Now I want to try the Jupyter/Ipython plus sympy for multiple reasons. I know how to use display(Math(r' some LaTeX math here ')) but what I want is to have the result/output of a cell in a nice mathematical form; something like the TraditionalForm[] command in Mathematica.
I would appreciate if you could help me know if/how I can get that right in a Jupyter notebook?
I think I found the proper solution and it is a sympy feature rather than Jupyter/IPython one. As explained here:
If all you want is the best pretty printing, use the init_printing() function. This will automatically enable the best printer available in your environment.
and
In the [Jupyter/]IPython notebook, it will use MathJax to render LATEX.
Then one can right click on the output and select Show Math As > Tex commands:
to get the LaTeX output.
P.S. A more proper formatting can be achieved via galgebra library. I will look into that and add it here later.
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).