Equation numbering in pelican with mathjax - mathjax

I use render_math Pelican plugin to use latex, however it is not (by default) providing equation numbering.
How can this be achieved?

If you add an eqnarray latex tag to your equation, as in $$ \begin{eqnarray} <your equation here> \end{eqnarray} $$, it will add a numbered equation to the MathJax equation.
(Side note: if it is a multi-line equation, use \nonumber to limit the numbering.)

Related

Editing multiple lines of same parameter

I'm working with a large dataset and multiple lines need change on a certain parameter. Something like this for example:
funct(35, circle, square, triangle);
funct(42, sphere, cube, prism);
funct(74, disc, rhombus, rectangle);
needs to become:
funct(35, circle, my_square, other_triangle);
funct(42, sphere, my_cube, other_prism);
funct(74, disc, my_rhombus, other_rectangle);
How could I go about doing this?
An additional vim approach. Visually select all of the lines you would like to change, and then type this:
:norm 2Wimy_<C-v><esc>Wiother_
Note that <C-v> and <esc> are ctrl-v and esc, not text. Or, if you want to do this on every line, do this:
:%norm 2Wimy_<C-v><esc>Wiother_
You could also do this on lines in a certain range. For example, lines 3-100:
:3,100norm 2Wimy_<C-v><esc>Wiother_
I'll speak about emacs because I just love emacs !
to enter commands in the prompt : Alt + x
For small datasets
You can install the multiple-cursors package. It's like the Ctrl+D in SublimeText. Here is the doc.
For big datasets with some controls
You can use built-in package query-replace. It will replace the string/regex you want with another. Documentation.
The advantage of this one is that you can choose if you want to replace or not each occurence.
For big datasets without control
The built-in packages replace-string and replace-regexp will replace the pattern of your choice with a string or another pattern.
replace-regexp
replace-string
If you just want to rename some variables, multiples-cursors, replace-string and query-replace are fine.
If you want to replace patterns in huge datasets, replace-regexp is fun, but nothing's better than a script (bash, js, python ...).
There are amazing books about sed and awk bash commands (sed & awk, 2nd Edition)
With Vim:
:%s/\vfunct\(([^,]+,\s*){2}\zs/my_/
The 2 above is the number of arguments you want to skip.
The catch: this breaks if some parameters are themselves function calls. There are plugins that allows you to cope with that situation.
Using vim's regex engine:
:%s/\v(%(\s*\w+,){PARAMETER_NUMBER})(\s+)(\w+)/\1\2NEW_PREFIX\3
Substitute PARAMETER_NUMBER with the index (starting from 0) of the parameter you'd like to change and NEW_PREFIX with the prefix you'd like to add to it.
For instance, running:
:%s/\v(%(\s*\w+,){2})(\s+)(\w+)/\1\2my_\3
Changes your example code into:
funct(35, circle, my_square, triangle);
funct(42, sphere, my_cube, prism);
funct(74, disc, my_rhombus, rectangle);
You can modify this to customize it in other ways by changing the order of the backreferences (the \1, \2 and \3) at the end of the command. \1 refers to the parameters before the one you're changing, \2 refers to the whitespace just before the parameter you're changing and \3 to the parameter itself.
I'm aware of multiple-cursors, and they look really cool, but I've been to lazy to learn them. Here's a solution using only Emacs built ins.
(defun align-regexp-comma (beginning end)
"Align columns using comma as a delimiter."
(interactive "*r")
(align-regexp beginning end
",\\(\\s-*\\)" 1 1 t))
(global-set-key (kbd "C-<return>") 'cua-rectangle-mark-mode)
Then select the region you of interest, do M-x align-regexp-comma, which should align the arguments, then you can use C-<return> to start the rectangle mark, which lets you edit several lines at once. If you then want to remove the aligning spaces, use query-regexp-replace (M-%) with ", +" -> ", ".

Where are line breaks allowed within Haskell expressions?

Background
Most style guides recommend keeping line lengths to 79 characters or less. In Haskell, indentation rules mean that expressions frequently need to be broken up with new lines.
Questions:
Within expressions, where is it legal to place a new line?
Is this documented somewhere?
Extended question: I see GHC formatting my code when it reports an error so someone has figured out how to automate the process of breaking long lines. Is there a utility that I can put haskell code into and have it spit that code back nicely formatted?
You can place a newline anywhere between lexical tokens of an expression. However, there are constraints about how much indentation may follow the newline. The easy rule of thumb is to indent the next line to start to the right of the line containing the expression. Beyond that, some style things:
If you are indenting an expression that appears in a definition name = expression, it's good style to indent to the right of the = sign.
If you are indenting an expression that appears on the right-hand side of a do binding or a list comprehension, it's good style to indent to the right of the <- sign.
The authoritative documentation is probably the Haskell 98 Report (Chapter 2 on lexical structure), but personally I don't find this material very easy to read.

Strange SVG path syntax used in Snap.svg tutorial?

While looking through the Snap.svg tutorial, I came across the following line of code that made me do a double take:
// Now lets create pattern
var p = s.path("M10-5-10,15M15,0,0,15M0-5-20,15")
What is M10-5-10,15? At first, I thought it may have been some kind of coordinate-range syntax, but that wouldn't really make much sense in this case, and I couldn't find anything remotely close to that in the SVG path spec. I also couldn't find anything of note in the Snap.svg docs.
Interestingly enough, that code does seem to draw the desired pattern...
The simplest answer is often the right one. There is no special syntax - the coordinates are just concatenated together with no white space.
The clue is the command: M is the moveto command, which doesn't normally draw anything. If you look in the spec, however, you'll notice the following:
If a moveto is followed by multiple pairs of coordinates, the
subsequent pairs are treated as implicit lineto commands.
So, a moveto can actually have multiple coordinate pairs, and anything after the first pair is treated as a lineto command. The mystery syntax is, in reality, just a concise (but less readable) way of writing M10,-5 -10,15 M15,0 0,15 M0,-5 -20,15, the hyphens being the negative signs.
Simply looking at the SVG path grammar also shows quite clearly that the arguments to moveto are coordinate-pairs, and coordinates are simple numbers.
I suppose the key thing to take away is that SVG paths don't really need whitespace or commas, unless the numbers would be ambiguous without them.

Syntax Highlighting with Fine Granularity

Is there a way to assign an individual character, as identified by a height and depth index, to a highlight group? Every match feature I have come across uses a regex pattern as input.
The reason I ask is because I am making a syntax coloring plugin that will make text an increasingly lighter shade of gray with increasing parenthesis depth. If vim has no such feature and another algorithm makes character-by-character highlighting unnecessary, please point me to it!
Vim has a whole set of special regular expression atoms that can specify buffer positions.
For lines, \%23l matches only in line 23. You can also use \%>23l for all lines starting from 23, and concatenate two of those with < and > to specify ranges.
For columns, there are the corresponding \%23c and \%23v. The former uses byte indices (what Vim somewhat confusingly calls "columns"), as returned by functions like col() and getpos(), the latter screen widths (from virtcol()).
By combining those atoms, you can select arbitrary blocks of text, and highlight them, e.g. with :call matchadd(...). See :help /\%l for details on the atoms.
For your plugin implementation, you may be able to get some ideas from the vim js context coloring plugin, which highlights JavaScript code according to its scope.

Search and Replace in Emacs with Icicles

I've been using Emacs for a while now and am trying out Icicles. When I run the sequence of commands
C-c`\([a-z]*\)
S-TAB
C-| x\1y
it transforms the scratch buffer from
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
to
;; Xy xy xy xy xy xy xy'xy xy xy xy, xy xy Xy xy.
;; Xy xy xy xy xy xy xy, xy xy xy xy XY-xy XY-xy,
;; xy xy xy xy xy xy xy'xy xy xy.
My understanding is that it should instead attach an 'x' to the start of each word and a 'y' to the end of each word. What am I doing wrong here? I have tried this with emacs -Q and gotten the same results. Also, icicle-search-replace-literally-flag is unchanged from its default value of nil. What am I doing wrong? Thanks!
Edit: Sorry, I omitted the group in the regexp in the original post; however, I did use it in the test and still get the same result.
I do not use icicles but the effect is reproducible with the ordinary query-replace-regexp.
The problem is that you just do not define any group in your regular expression which you refer to in the replacement. Therefore the group reference \1 in the replacement string is empty.
Furthermore, you should use [a-z]+ instead of [a-z]* since [a-z]* also matches the empty string what you probably do not want.
To put the stuff you want to refer to into a group wrap it by paranthesis \(\). In your example the regular expression would look like \([a-z]+\). With this regular expression you can directly use your replacement string.
The alternative is to leave the regular expression as it is and refer to the whole match with \& instead of \1 in your replacement string.
Be sure that your version of file icicles-cmd2.el is dated after 2013-12-10. I fixed a bug wrt \N replacements on that date.
Other suggestions:
Proceed slowly, rather than immediately jumping into complex replacements etc. Icicles search and replacement are different from what you might be used to or expect.
Check the current values of all of the user options that affect Icicles search and replacement.

Resources