How to define custom macro for mathjax expression inside asciidoc? - mathjax

I have some mathematical expression that I would like to reuse in my asciidoc document:
:stem: latexmath
[latexmath]
++++
E^{\unicode{x2307}\unicode{x2307}\unicode{x2307}}
++++
In order to get equations that are easier to read I would like to use a shortcut, e.g.
:stem: latexmath
[latexmath]
++++
E^{\myCustomSymbol}
++++
or
:stem: latexmath
[latexmath]
++++
E^{include::myCustomSymbol.ad}
++++
=> How can I use asciidoc imports inside mathematical expressions or
=> How can I define mathjax macros inside asciidoc (is it possible to adapt the mathjax configuration with some special commands) ?
Related questions:
how to define own asciidoc macro
How to define custom macros in MathJax

Try
:stem: latexmath
[latexmath]
++++
\newcommand{\myCustomSymbol}{{\unicode{x2307}\unicode{x2307}\unicode{x2307}}}
E^{\myCustomSymbol}
++++
[latexmath]
++++
E^{\myCustomSymbol}
++++
You only need to define the symbol once, then can use it from then on.

Related

How to pretty-print inlined variables when formatting strings

Normally one can print strings the following way: println!("{:#?}", foo) where the {:#?} syntax will make a pretty-print of the value. But I know it's also possible to inline the variable directly in the string between the curly braces, instead of listing it as a second argument to the macro, like so: println!("{foo}").
My question is - can I combine the pretty-print syntax and inlining the variable in the string?
I found out about the shorthand syntax from clippy's docs, but I couldn't find (or understand) how to combine it with pretty-print (if it's at all possible).
Simply place the variable name before the colon:
fn main() {
let foo = 3;
println!("{foo:#?}");
}
Note:
:#? is pretty-printed Debug output
:? is normal Debug output
no modifier is Display output
Display is for user-facing output
Debug is for output when debugging, also used for panic messages

Replacing html content using sed and regex

I am trying to replace the content of some HTML content using sed in a bash script. For some reason I'm not getting the proper result as it's not replacing anything mainly the regex part
HTML i want to replace
<h3 class="indicate-hover css-5fzt5q">For the Most Complex Heroines Animation
<h3 class="indicate-hover css-1pvrrwb">The Psychology Behind Sibling
to
head For the Most Complex Heroines Animation
head The Psychology Behind Sibling
i used
sed -e 's/<h3 class="indicate-hover css-([a-b0-9]+)">/head/g'
mainly ([a-b0-9]) this part is getting failed in execution , i must be missing something out,i want to get it more specific , i have "<p class="summary-class css-1azn4ub">How many words can" i want to substitute it to 'tail ' and have many more other tags . The regex part is giving me the pain
Using sed
$ sed 's/.*-[[:alnum:]]\+">/head /' input_file
Output
head For the Most Complex Heroines Animation
head The Psychology Behind Sibling
You need to use \+, unless you use sed -E
\+ is a valid quantifier in the (default) Basic regular expressions
+ is a valid quantifier in Extended regular expressions

Equation numbering in pelican with 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.)

Own simple template system in vim - include file

I've read vim-wiki about dynamic templates and I want similar, simple "template-system". I've created a function:
function! Read_template(file)
execute '0r /home/zsolt/.vim/skeletons/'.a:file
%substitute#\[:EVAL:\]\(.\{-\}\)\[:END:\]#\=eval(submatch(1))#ge
%substitute#\[:READ:\]\(.\{-\}\)\[:END:\]#??????#ge
endfunction
I want to include a file from a template. The EVAL works well but how can I solve the READ function? It isn't important to eval the included file.
An example:
main.tex:
\documentclass[a4paper]{article}
....
exam.tex:
% Created [:EVAL:]strftime('%Y. %B. %d.')[:END:]
[:READ:]/path/of/main/main.tex[:READ:]
I exec Read_template("exam.tex") and want that exam.tex includes main.tex.
How can I do this?
You'll need to read the file and insert its contents. As you cannot use :read (it will read entire lines and cannot be called from within a substitution), you have to use the lower-level readfile() Vimscript function, like this:
%substitute#\[:READ:\]\(.\{-\}\)\[:END:\]#\=join(readfile(submatch(1)),"\n")/#ge
You'll have to parse each line imported and apply what needs be :
- expression substitution
- inclusion of other templates, etc. (which will mean that you'll have to remove and add lines on the fly. In the last version of mu-template template expansion engine, the expansion is done in-memory)
FYI, my work of mu-template already has this feature: http://code.google.com/p/lh-vim/wiki/muTemplate#Completely_useless_recursive_example

Vim errorformat: include part of expression in message string

With vim's errorformat syntax, is there any way to use part of the message in filtering results?
As an example, some linker errors don't have anything explicit to distinguish them as an error on the line, other than the error itself:
/path/to/foo.cpp:42: undefined reference to 'UnimplementedFunction'
or
/path/to/foo.cpp:43: multiple definition of 'MultiplyDefinedFunction'
Using an errorformat of:
set efm=%f:%l:\ %m
would catch and display both of these correctly, but will falsely match many other cases (any line that starts with "[string]:[number]: ").
Or, explicitly specifying them both:
set efm=
set efm+=%f:%l:\ undefined\ reference\ to\ %m
set efm+=%f:%l:\ multiple\ definition\ of\ %m
removes the false positives, but the 'message' becomes far less useful -- the actual error is no longer included (just whatever is after it).
Is there anything in the syntax I'm missing to deal with this situation?
Ideally I'd like to be able to say something along the lines of:
set efm+=%f:%l:\ %{StartMessage}undefined\ reference\ to\ %*\\S%{EndMessage}
set efm+=%f:%l:\ %{StartMessage}multiple\ definition\ of\ %*\\S%{EndMessage}
... where everything matched between StartMessage and EndMessage is used as the error's message.
The errorformat can also use vim's regular expression syntax (albeit in a rather awkward way) which gives us a solution to the problem. We can use a non-capturing group and a zero-width assertion to require the presence of these signaling phrases without consuming them. This then allows the %m to pick them up. As plain regular expression syntax this zero-width assertion looks like:
\%(undefined reference\|multiple definition\)\#=
But in order to use it in efm we need to replace \ by %\ and % by %% and for use in a :set line we need to escape the backslashes, spaces and vertical bar so we finally have:
:set efm=%f:%l:\ %\\%%(undefined\ reference%\\\|multiple\ definitions%\\)%\\#=%m
With that the error file
/path/to/foo.cpp:42: undefined reference to 'UnimplementedFunction'
/path/to/foo.cpp:43: multiple definition of 'MultiplyDefinedFunction'
notafile:123: just some other text
comes out as the following in :copen:
/path/to/foo.cpp|42| undefined reference to 'UnimplementedFunction'
/path/to/foo.cpp|43| multiple definition of 'MultiplyDefinedFunction'
|| notafile:123: just some other text
I've been using sed to rewrite the output in cases like this where I want to get some arbitrary output that's not nessicarily homogenous into the quickfix window.
You could write make.sh that fires off make (or whatever your're using to build) and trims off stuff you're not concerned with:
make | sed '/undefined reference\|multiple definition/!d'
(Deletes lines not containing 'undefined reference' or 'multiple definition')
If that's going to get too unweildly because of the number of error strings you care about, you could do the inverse and just kill stuff you don't care about:
make | sed 's/some garbage\|other useless message//'
then :set makeprg=make.sh in vim

Resources