I want to number the LaTeX equation, I searched internet that I shall use
%%javascript
MathJax.Hub.Config({
TeX:{equationNumbers:{autoNumber:'all'}}
});
I tested with an equation also with \eqref{}:
In equation $\eqref{eq:sample}$, we find the value of an interesting integral:
\begin{equation}
\int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
\label{eq:sample}{\tag{99}}
\end{equation}
The output in JupyterLab is
So far everything looks alright, however I start any another cell, use \eqref{eq:sample} or \ref{eq:sample} again.
In equation $\eqref{eq:sample}$, we find the value of an interesting integral:
it turns out to be a bunch of question marks.
So I tested in Jupyter Notebook as well, as long as I call the reference from another cell, MathJax failed to link the reference.
How can I solve the problem? Any suggestions?
First, at the top of your notebook, put the following:
%%javascript
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }
});
Then make equations in your Jupyter cells with things like:
\begin{equation}
\ddot{x} + a\dot{x} + bx = 0
\end{equation}
You will end up with numbered equations in your cells, but starting with 1 in each cell. To final step is you need to press the following reset equation numbering toolbar button that is in your Jupyter toolbar:
The equations all magically sort in order, across cells!
Note if you aren't seeing the reset numbering toolbar button, it means you haven't installed the equation number notebook extension. For instructions on how to install it, see this answer:
https://stackoverflow.com/a/42940005/1886357
Related
Not sure if the answer here Jupyter notebook not printing underscores? is related:
The problem is not with Jupyter notebook but with the way the underscore is rendered in the example. The browser decided not to show the underscore for that particular resolution
... but here it goes: I try to enter the equation $$ \mathtt{A\_b} = \frac{A}{b} $$ in a Markdown cell in Jupyter notebook; and the rendering I get is this:
Don't know about you, but that looks like a dash/minus sign to me, not like an underscore.
So, how can I get a proper underline rendered in an equation in Jupyter notebook Markdown (where the equation is written as Latex, but rendered as MathML)?
Found a workaround - but I'd still love to hear a proper answer by someone who knows better ...
In the meantime - simply don't include the underscore inside \mathtt; that is, use:
$$ \mathtt{A}\_\mathtt{b} = \frac{A}{b} $$
... which results with:
Is there a way to debug the code line by line in R studio environment ??
I know there are breakpoints, Next, continue etc to debug. But I am looking for a line by line debug option like the one in Visual Studio.
Thank you
For R-Studio newbies like me that are used to other IDEs:
a) Set a break point by clicking on the border or pressing Shift+F9 (=>red break point dot is shown)
b) As equivalent to "Debug" in other IDEs:
Click source or
Press Ctrl+Shift+Enter or
Activate source on save and save
c) Have a look at the Console view. There are common debug options:
Execute Next Line F10
Step Into Function Shift+F4
Finish function Shift+F6
Continue Shift+F5
Stop Debugging Shift+F8
(Unfortunately I did not find a way to adapt the key shortcuts for those options. They are not listed under Tools=>Modify Keyboard shortcuts.)
d) There does not seem to be a "hover over expression" feature while debugging. You can have a look at the Environment view to see the value of a variable and use the Console to evaluate expressions while debugging.
If you want to run the script without debugging and without clearing the break points, select all lines Ctrl+A and use the Run button. (Seems to be complicated to me.... I would expect an extra run button or key shortcut for that but could not find one.)
If there is no selection, the Run button only executes the current line. You can press that button several times to step through the code and see the corresponding console output (=pseudo debugging).
Also see documentation at
https://support.rstudio.com/hc/en-us/articles/200484448-Editing-and-Executing-Code
https://support.rstudio.com/hc/en-us/articles/205612627-Debugging-with-RStudio
and related questions:
Disable all breakpoints in RStudio
Debugging a function in a different source file in R
Rstudio debug - missing step into button
https://support.rstudio.com/hc/en-us/community/posts/202156378-how-do-i-clear-the-console-
The debug package is probably what you want. If you are debugging via this package an extra window opens in which your code is displayed and then you can debug line by line in combination with RStudio.
EDIT:
See below example code for how to debug with the debug package:
install.packages("debug")
library(debug)
fun <- function(x) {
y <- x + 1
z <- y + 1
return(z)
}
mtrace(fun)
fun(2)
For very large equations generated by sympy, mathjax in the ipython notebook sometimes fails to render the equation. Instead, it shows the latex source of the equation in a box (which stretches far off the page). I can copy and paste that source into a real latex document, and it renders just fine (though I might have to use the geometry package to make the output PDF extraordinarily wide).
I've actually successfully rendered longer equations, but these particular ones I found were long and also had very large numbers of \left \right pairs in them. I'm not sure if that has anything to do with the failure, but it seems relevant.
What is going on? How can I debug mathjax? And how can I get it to render those equations?
Using the debugging tip found in this question, I found that the buffer was too small, which led me to this mathjax page, where I found the solution. After I increase mathjax's MAXBUFFER value, the equations render just fine. To do this (and turn debugging on), I just put the following in my ~/.ipython/profile_default/static/custom/custom.js.
MathJax.Hub.Config({
TeX: {
noErrors: {disabled: true}, // Show error messages
MAXBUFFER: 25*1024, // Set size of buffer in bytes
},
});
[Note: Your profile may be elsewhere. To find it, run ipython profile locate. If you don't have the custom.js file or its directories, you may need to create them.]
UPDATE (April 2013): As per answer below, RStudio no longer jumps cursor on selection.
I'm running RStudio 0.97.168.
I like to use the script editor in RStudio like a console. Thus, I run a line of code and then edit it a little bit and re-run it. I often also explore objects by selecting some of the code and running the selection and then progressively altering the selection. At present RStudio always moves the cursor after running a line of code. The cursor can move to a variety of places. Typically the cursor moves to the next line of R code, but depending on the context, it could move to the end of the code block or the next line. It's really frustrating having to constantly move the cursor back to where I want it.
While I often appreciate the default cursor movement behaviour, I'd like to have the option to run the selection or the current line without the cursor moving.
I've raised this as a suggestion on RStudio support.
I'd like to be able to have a shortcut key like "Cmd+Alt+Enter" that runs the current line or selection and does not move the cursor in the script editor.
I realise that this is not currently supported, but I was wondering whether there might be some creative hack that could enable the cursor not to move after running a command or even a patch or perhaps some sort of external macro.
For anyone who ends up here in 2020:
Ctrl(or Cmd) + Enter: Will run current line and jump to the next one. If a code portion is selected, run the selected code without jumping further.
Alt + Enter: – Will run the current line of code without moving the cursor to the next line, useful if you want to run it multiple times.
(Source)
For this kind of flexibility, I suggest you use the editor Sublime Text 2, add in the package installer by Will Bond and then install the SublimeREPL package which will allow you to use an R interpreter within ST2 (or BASH prompt, Python / Ruby / whatever interpeter, concurrently if you wish).
You can then alternate between your code and the interpreter without lifting your fingers from the keyboard and your cursor will be at the same point every time when you want to switch back.
Sublime Text will also allow you to write a custom keybinding to automate this task.
I cannot recommend using Sublime Text 2 highly enough when coding for R. You can even pass files directly from ST2 into RStudio very easily if you like using the plot panes (very easy to do with the SidebarEnhancements package in ST2).
RStudio is awesome for many things -- especially now with Knitr, builds etc etc. But ST2 with an R REPL is many orders of magnitude more powerful for general code writing / editing than RStudio.
Sorry it's not RStudio specific, but it is a nice workaround!
I updated to version 0.98.83 of RStudio using the daily build section.
It appears that at some point in recent versions of RStudio, the cursor no longer jumps when code is run from a selection in the script window.
That's great news.
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.