Disable automatic LaTeX symbol replacement in VS Code - visual-studio-code

When editing RMarkdown files in Visual Studio Code, the editor automatically replaces many LaTeX-style sequences with their unicode 'equivalents'. E.g., when I type \sum followed by a space, it is converted to ∑. While this is convenient in some cases, it is catastrophic when trying to embed LaTeX source into my file for rendering later on. Typing something like $\sum \sqrt {x_i}$ is converted to $∑ √ {x_i}$, which renders quite differently. Even pressing "escape" when the suggested replacements show up does not prevent the substitution.
Is there a way to turn this off? I've looked through the settings quite thoroughly and cannot find a way to do so. Any help would be appreciated!
(The workaround I've come up with is to copy a single space character and paste it after my symbol instead of pressing the space key on the keyboard.)
Visual Studio Code Version: 1.63.2
Mac OS 10.14.6

It turns out I had an extension installed called "Fast Unicode Math Characters" which, true to it's name, was inserting unicode math characters 😅
Disabling this fixed the issue.
(I decided to answer my own question rather than deleting the question in case someone else has a similar issue)

Related

Prettier keeps replacing asterisk characters with underscores

I'm trying to write some markdown text in Visual Studio Code and whenever I write this:
*some text*
It's being replaced by this as soon as I save the file:
_some text_
I narrowed it down to be caused by the Prettier extension. I tried looking for a setting that might control this but didn't find any - well none that was obvious to relate to the issue.
I'd really like to keep Prettier enabled for markdown files as it also keeps tables nice and tidy.
Is there a way around this one issue?
UPDATE:
I am aware that both asterisk and underscore works for italic emphasis when the file is shown through a markdown viewer, but when reading the file as pure text, the asterisk feels more natural to me for emphasis and I'd much prefer keep using it if possible.
I also feel the same way, but from what I can tell Prettier simply does not have that option (https://prettier.io/docs/en/options.html)
Prettier is not a kitchen-sink code formatter that attempts to print your code in any way you wish. It is opinionated.
https://prettier.io/docs/en/option-philosophy.html
Given that philosophy, I doubt this will ever change. As for me, I think I'm going to try to just get over it.
I think the only way to avoid this would be to use something different, for example:
https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint

How do I use Latex in a Jupyter notebook inside Visual Studio code?

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

VS code `\` underlining for insufficiently long

I am using Lean, an open source theorem prover and programming language on VS Code. Lots of commands require '\' to write math symbols, in the same way that LaTeX does.
The essential difference between Lean on VS Code and LaTeX is that in order to have the math symbol compile (e.g the difference between getting \forall and the maths 'forall' sign) is that an underline must appear whilst you're typing the characters after the \ sign.
The issue that I'm experiencing is that this underline
1) Doesn't always appear when I type \
2) Disappears way too quickly.
My question is: Is this a bug, or is there a way to change the settings in VS code such that an underline always appears after the \?
Any answers would be much appreciated.

Shortcut for clike languages comments not working/implemented?

I'm using the Brackets code editor to code in C++ and I'm having a hard time having the shortcut for lineComment and blockComment working...
The shortcuts are [Ctrl+/] and [Ctrl+Shift+/], they work perfectly for CSS, JS.. etc but not with C++ files.
I looked into the clike.js file in the CodeMirror folder of Brackets, the blockCommentStart, blockCommentEnd and lineComment are correctly defined.
Is it a known issue? has anyone found a workaround?
Before that,I was coding with Notepad++ and this feature was the one I used the most. It's really hard not to have it anymore
You said you saw that blockCommentStart, blockCommentEnd and lineComment are correctly defined in clike.js. From CodeMirror documentation
This file defines, in the simplest case, a lexer (tokenizer) for your
language—a function that takes a character stream as input, advances
it past a token, and returns a style for that token. More advanced
modes can also handle indentation for the language.
It is used to highlight the c++ file. But also it could be used to auto comment line with shortcut. However it is probably not implemented for C++. For this feature comment addon from CodeMirror might be used http://codemirror.net/addon/comment/comment.js since The addon also defines a toggleComment command, which will try to uncomment the current selection, and if that fails, line-comments it.
This was a Brackets bug, but it was fixed in the Sprint 39 release.
(Fwiw though, language metadata in Brackets is defined in a file called languages.json - although Brackets extensions can add to / modify this metadata as well).

How to get around Eclipse swallowing double quotes for ${selected_text}

I am using Eclipse 3.6.1 Build id: M20100909-0800 and Aptana Studio 2.0.5 which is based on Eclipse 3.5.2 (both on OS X) and in both programs the external tools feature seems to swallow double quotes and whitespace for the ${selected_text} variable.
Isn't the ${selected_text} variable essentially useless with the mentioned behaviour?
Is there a way around that or maybe a hidden setting somewhere?
Thanks for reading.
This could easily be considered a safety/security feature.
I suggest "${selected_text}".
...but if it's eating ALL whitespace, that won't really help. Huh. Maybe it's clever enough to detect the quotes and preserve the whitespace... but probably not.
Okay, I did a little poking around. Quotes within the argument list itself are preserved, as per my initial suggestion above. I found the following auto-generated argument list that was working Just Fine:
-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog
-debug "${workspace_loc:/com.cardiff.bpm.ide.webforms.ui/debug.options}"
But if your text selection contains quotes, I'd expect it to be handled as per the underlying OS. Windows "cmd" does some... creative things with them for example. My *nix-fu is Not Mighty, so I couldn't tell you what OS X will do under the covers, but I suspect that's where you'll find your solution.
You may have to do something goofy like URL-encode your selection, and use some command line tool to un-encode it before passing it to your desired external tool once the text is out of Eclipse's clutches.
A (very) quick look around my 3.6.1 UI didn't turn up that would do this automagically for you, but there's probably a plugin out there somewhere that'll add that feature to an editor's context (right click) menu.
I'd expect the HTML editor to have this ability already... but I don't see anything other than "smart insert mode" that sounds promising, and I don't see that working either.
That doth bloweth goats, most heartily, yay for weeks on end. E'en till yon goat hath a rash, most unpleasant in both severity and locality. Verily.
I don't think you're getting my proposed solution:
Set up your tool so it'll de-url-encode-ificate the incoming string with some proposed command line tool.
In your editor (in eclipse), URL-encode the text you wish to select and pass to the tool. Manually.
Run the tool on the selected (url-encoded) text.
Revert the selected text. Also manually. Probably just "undo".
"1" is why I was looking for some eclipse UI way of url-encoding a selection. The HTML Editor won't even do it when you paste into an attribute string. Sheesh.
Two Other Options:
Fix the bug yourself. Open Source and all that.
Write a plugin that exposes it's own version of ${selected_text} that doesn't strip out all the strings.
Hey! SED! Replace the quotes with some random (unused in any selection you might make) high-ascii character and sed it back to a double quote instead of the proposed de-url-encode-ificationizer. You'd still have to manually edit/undo the text, but at least you won't have to """ Actually search/replace over a given selection makes that less painful than one might think.
I'm not sure what the scope of #2 is, but I'd image if you don't have any eclipse plugin experience the thought might be rather daunting. There might even be a sample plugin that exposes such a variable, though I haven't checked.
I don't think we're communicating.
You don't select text with quotes in it. You select mangled text, and sed demangles it back into quotes for you.
For example, you have the string print("hello world"); in your editor and want to send that to your tool.
change it to print(~hello world~); in your editor. Manually or via a script or whatever.
select it
run your tool, maybe wrapped in a script that'll sed the ~s back to "s.
change it back to print("hello world");.
This is a manual process. It's not pretty. Bug workarounds are like that. You can probably come up with a monkey script to convert quotes to Something Else, and "undo" is easy. You might even be able to get your script attached to a keyboard short cut... dunno. And ~ is a lousy choice for a replacement character, it's just the first thing I could think of that was rare enough to be a decent example.
Are we communicating yet?
For the record, I put together a patch using some guidance from a gentleman in the bug comments.
I don't know if it will be accepted, but it fixes things for me so maybe someone else may find it useful.
Again, this is only for Mac OS X Eclipse.
Start Eclipse.
Go to Import > Plug-ins and Fragments.
Import From: Active Platform
Fragments to import: Select from all plug-ins
Import As: Projects from a repository
Next >
Pick org.eclipse.debug.ui and org.eclipse.debug.core
Once the projects are in your workspace, apply the two patches that compose proposed patch v1, found at the bug tracker page for bug 255619
Go to Export > Deployable plug-ins and fragments and make a jar out of your changed packages.
Hope it helps.