How to add table in web page using mathjax - mathjax

I am a beginner. I am trying to build a table using math Jax but it can't compile. how can I add a table?
\begin{center}
\begin{tabular}{ | m{7em} | m{5em}| m{9em} | }
\hline
Set & operation & Identity \\
\hline
\(\mathbb{Z}\) & \(+\) & \(0\) \\
\hline
\(\mathbb{Q}\) & \(+\) & \(0\) \\
\hline
\(\mathbb{R}\) & \(+\) & \(0\) \\
\hline
\(\mathbb{Z}\) & \(\times \) & \(0\) \\
\hline
\(\mathbb{Q}\) & \(\times\) & \(0\) \\
\hline
\(\mathbb{R}\) & \(\times\) & \(0\) \\
\hline
\end{tabular}
\end{center}

I made a table generator for MathJax using MathJax's array : https://isaurssaurav.github.io/mathjax-table-generator/
Usage:
Add required columns and Rows.
You can add values to cells when table appears
Click Generate button to generate a mathjax code for table.
Repo Link :https://github.com/isaurssaurav/mathjax-table-generator
( Any changes are welcome )

MathJax only implements the macros used for math layout, not text layout, so things like \begin{tabular} and \begin{center} are not supported. Instead, you can use an array environment, like:
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS_CHTML-full"></script>
\[
\begin{array}{|c|c|c|}
\hline
\text{Set} & \text{Operation} & \text{Identity} \\
\hline
\mathbb{Z} & + & 0 \\
\hline
\mathbb{Q} & + & 0 \\
\hline
\mathbb{R} & + & 0 \\
\hline
\mathbb{Z} & \times & 1 \\
\hline
\mathbb{Q} & \times & 1 \\
\hline
\mathbb{R} & \times & 1 \\
\hline
\end{array}
\]
On the other hand, it may be better to use an HTML table with math inside it rather than trying to use MathJax to do the entire table.

Try this:
$$\begin{array} {|r|r|}\hline a & c \\ \hline b & d \\ \hline \end{array}$$

Related

How can I replace/change/overwrite the selected visual block from default register in vim?

Is it possible replace/change text selected via visual block with text held in the register?
Edit:
The normal p on top of the selected text does not work on my vim:
VIM - Vi IMproved 8.1 (2018 May 18, compiled Nov 3 2021 04:38:26)
macOS version
Example: select the first 2 lines of column 3 (marked with |-|) in file1 with visual block mode (Ctrlv). Then replace/change them with text from default register previously yanked from column 3 in file2 (across first 2 lines) without previously deleting the block to be replaced?
I have to do this repeatedly between two files but only on certain lines from certain columns.
file1
|-|
1 aaa & bbb -
2 aaa & bbb -
3 aaa & zzz
4 aaa & zzz
5 aaa & bbb
6 aaa & bbb
file2
|-|
1 aaa & ccc -
2 aaa & ccc -
3 aaa & zzz
4 aaa & zzz
5 aaa & ccc
6 aaa & ccc
desired change in file1
1 aaa & ccc
2 aaa & ccc
3 aaa & zzz
4 aaa & zzz
5 aaa & bbb
6 aaa & bbb
So far did this:
I select the desired columns and lines via visual block and delete them in file1. Then, I switch tab to yank the needed columns (file2), switch back to file1, again and select the desired position and paste the text p.
I was wondering if there is a smarter way to do this. My ideal way would be: I go to file2 yank the needed columns and lines. Switch tab to file1 and select the text to be replaced via visual block mode. Then I simply use something like r+p or c+p to replace the selected text with the text from default register.
Another option I found is from this answer https://unix.stackexchange.com/questions/26654/how-can-i-paste-overwriting-with-vim/26716#26716 using the following steps
Yank desired block of lines to be pasted
Move to the other tab and select text to be replaced delete using d. The register " holds now the deleted line, but register 0 still holds the previously yanked line.
Paste from 0 register using "0P
But this still forces me to delete the undesired text first.
Deleting the selected lines in column 3 is not necessary.
Try this:
Open file1 in vim then open file2 by typing :tabe file2
In file2: Select the lines you want to yank in visual block mode (Ctrl+v use y to yank the selected lines).
Switch tabs using g t
In file1: Select lines to be replaced in visual block mode.
Replace the lines from default register using ""p

How to wrap each line in quotes in SublimeText?

Input:
boston beach summer figural yellow blue
boston floral flowers still still-life food pink figural
boston horse pink purple house flowers floral figural
Expected output:
"boston beach summer figural yellow blue"
"boston floral flowers still still-life food pink figural"
"boston horse pink purple house flowers floral figural"
The actual input file has 600+ lines, and I'm looking at a quick way to wrap each line in quotes? Does the method involve using multiple cursors? How about macros?
I would use a multiple cursors approach like this:
Windows
Ctrl + A (Select everything)
Ctrl + Shift + L (Split into lines)
End (Put the cursor at the end of the line)
" (Add the quote at the end of the line)
Home (Go to the first character of the line)
Home (Go to the beginning of the line... like if you have tabs or spaces)
" (Add the quote at the beginning of the line)
Mac
Cmd + A (Select everything)
Cmd + Shift + L (Split into lines)
Cmd + → (Put the cursor at the end of the line)
" (Add the quote at the end of the line)
Cmd + ← (Go to the first character of the line)
Cmd + ← (Go to the beginning of the line... like if you have tabs or spaces)
" (Add the quote at the beginning of the line)
Method 1:
no multiple cursors
+ best performance (use for large files)
- slightly clumsy
Replace (.*) with "\1"
Method 2:
multiple cursors
+ best in regards to usability/comfort
- slower for bigger files
- wont work if the file has empty lines
Ctrl+a, Ctrl+Shift+l, "
Method 3:
multiple cursors
+ close to #2 as usability, but works always
- slower for bigger files
Ctrl+a, Ctrl+Shift+l, End, ", Home, "
None of these worked in Sublime Text 3 for a multi-column TSV file with tab spacing.
I found this worked for column 1:
Find: ^\s*\S+
Replace: "$0"

How do you apply a macro x amount of times per line where x depends on the line

Say I have something like
a & 1234567890
b & 1234567890
c & 1234567890
d & 1234567890
e & 1234567890
f & 1234567890
Is there a way to use a vim macro such that I can run a macro/command x amount of times per line, where x depends on the line?
In this case, I run 2wx^ on each line x times, where x is the line number such that the result becomes
a & 234567890
b & 34567890
c & 4567890
d & 567890
e & 67890
f & 7890
Thanks in advance
If your macro is recorded in register q, then you can run:
:exec 'normal ' . line('.') . '#q'
on any line you want. Your macro will want the cursor kept on 1st column before being run.
You can also probably do it - better - in a different way, if you describe what you want to do. For example, perhaps you could skip the macro altogether and use something like this instead:
:exec 'normal ^2w' . line('.') . 'xj'
If you need a line offset (e.g. of 1), you could use:
:let nr = line('.') - 1 | execute 'normal ^2w' . nr . 'xj'

How to reduce time in livecode

I need to preserve some text, so i get that text from scrolling field and stored in arrays and variables before my editing, after my editing, i restore the text in that places. I am using this code for this process, it works fine but it tooks lot of time. How to reduce that time?
command Store
global ELine,m,EELine,myEELength,myELength,EQLine,myEQLength,EALine,myEALength,ESLine,ESuLine,myESLength,myESuLength,TSLine,myTSLength,stsLine,sta,stab,Tta
global wPreserve,woPreserve,endwPreserve,cnt
put the text of field "MytextField" into woPreserve
put the number of lines of woPreserve into cnt
--answer cnt
repeat with x = 1 to the number of lines of woPreserve
if line x of woPreserve contains "begin{thebibliography}" then
put line x to cnt in woPreserve into endwPreserve
delete line x+1 to cnt in field "MytextField"
--answer endwPreserve
end if
end repeat
repeat with x = 1 to the number of lines of woPreserve
if line x of woPreserve contains "begin{document}" then
put line 1 to x-1 in woPreserve into wPreserve
delete line 1 to x-1 in field "MytextField"
--answer wPreserve
end if
end repeat
set the caseSensitive to true
put "" into ELine
replace "\$" with "{\XXdollarXX}" in field "MytextField"
put the text of field "MytextField" into Tvar
--put replaceText(Tvar,"[a-z,A-Z]\$"
put replaceText(Tvar,"\n","^EOL") into field "MytextField"
put the text of field "MytextField" into Tvar
put the number of paragraphs in Tvar into ppara
repeat with p = 0 to ppara
put paragraph p of Tvar into q
--put replaceText(q,"\s\n","") after aa
put replaceText(q,"\n","") after aa
end repeat
--put aa into field "MytextField"
replace "^EOL\begin{Seqnarray}" with cr & "\begin{Seqnarray}" in field "MytextField"
replace "\end{Seqnarray}^EOL" with "\end{Seqnarray}" & cr in field "MytextField"
replace "^EOL\begin{subequation}" with cr & "\begin{subequation}" in field "MytextField"
replace "\end{subequation}^EOL" with "\end{subequation}" & cr in field "MytextField"
replace "^EOL\begin{equation}" with cr & "\begin{equation}" in field "MytextField"
replace "\end{equation}^EOL" with "\end{equation}" & cr in field "MytextField"
replace "^EOL\begin{eqnarray}" with cr & "\begin{eqnarray}" in field "MytextField"
replace "\end{eqnarray}^EOL" with "\end{eqnarray}" & cr in field "MytextField"
replace "^EOL\begin{align}" with cr & "\begin{align}" in field "MytextField"
replace "\end{align}^EOL" with "\end{align}" & cr in field "MytextField"
replace "^EOL\begin{Table}" with cr & "\begin{Table}" in field "MytextField"
replace "\end{Table}^EOL" with "\end{Table}" & cr in field "MytextField"
replace "^EOL\begin{table}" with cr & "\begin{table}" in field "MytextField"
replace "\end{table}^EOL" with "\end{table}" & cr in field "MytextField"
--replace "\begin{Seqnarray}" with cr & "\begin{Seqnarray}" in field "MytextField"
replace "\end{Seqnarray}" with "\end{Seqnarray}" & cr in field "MytextField"
--replace "^EOL\begin{subequation}" with cr & "\begin{subequation}" in field "MytextField"
replace "\end{subequation}" with "\end{subequation}" & cr in field "MytextField"
--replace "^EOL\begin{equation}" with cr & "\begin{equation}" in field "MytextField"
replace "\end{equation}" with "\end{equation}" & cr in field "MytextField"
--replace "^EOL\begin{eqnarray}" with cr & "\begin{eqnarray}" in field "MytextField"
replace "\end{eqnarray}" with "\end{eqnarray}" & cr in field "MytextField"
--replace "^EOL\begin{align}" with cr & "\begin{align}" in field "MytextField"
replace "\end{align}" with "\end{align}" in field "MytextField"
--put the text of field "MytextField" into aa
put 0 into k
put 0 into z
put 0 into n
put 0 into j
put 0 into l
put 0 into Ta
put 0 into stab
put the text of field "MytextField" into aa
repeat for each lines ET in aa
if ET contains "\begin{subequation}" then
add 1 to k
put "-----SubDisplayEquation-----" & k into es
replace ET with es in field "MytextField"
put ET & cr after ESLine
end if
if ET contains "\begin{Seqnarray}" then
add 1 to z
put "-----SDisplayEquation-----" & z into eSu
replace ET with eSu in field "MytextField"
put ET & cr after ESuLine
end if
if ET contains "\begin{equation}" then
add 1 to n
put "-----DisplayEquation-----" & n into eo
replace ET with eo in field "MytextField"
put ET & cr after EELine
end if
if ET contains "\begin{eqnarray}" then
add 1 to j
put "-----EqnarryDisplayEquation-----" & j into er
replace ET with er in field "MytextField"
put ET & cr after EQLine
end if
if ET contains "\begin{align}" then
add 1 to l
put "-----AlignDisplayEquation-----" & l into ea
replace ET with ea in field "MytextField"
put ET & cr after EALine
end if
if ET contains "\begin{Table}" then
add 1 to Ta
put "-----Table-----" & Ta into Tta
replace ET with Tta in field "MytextField"
put ET & cr after TSLine
end if
if ET contains "\begin{table}" then
add 1 to stab
put "-----_table_-----" & stab into sta
replace ET with sta in field "MytextField"
put ET & cr after stsLine
end if
end repeat
put the text of field "MytextField" into ss
put "" into yy
put 0 into tmp
repeat with i = 1 to the number of chars in ss
if char i of ss contains "$" then
add 1 to tmp
if tmp = 1 then
put "^SOE" & CR & char i of ss after yy
else
put char i of ss & CR & "^EOE" after yy
put 0 into tmp
end if
else
put char i of ss after yy
end if
end repeat
put yy into the field "MytextField"
put 0 into m
repeat for each lines iT in yy
if iT contains "$" then
add 1 to m
put "---In_Line_Equation---" & m into so
replace IT with so in field "MytextField"
put iT & cr after ELine
end if
end repeat
--answer ELine
put 0 into m
put the text of field "MytextField" into SSEE
put replaceText(SSEE, "\^SOE\n","") into SSEE
put replaceText(SSEE, "\n\^EOE","") into SSEE
put replaceText(SSEE, "\^EOL",cr) into SSEE
--answer SSEE
put SSEE into field "MytextField"
end Store
command Restore
global ELine,m,EELine,myEELength,myELength,EQLine,myEQLength,EALine,myEALength,ESLine,ESuLine,myESLength,myESuLength,TSLine,myTSLength,stsLine,sta,stab,mystsLength
global wPreserve,x,woPreserve,endwPreserve,cnt
put cr into line 0 of field "MytextField"
put wPreserve into line 0 of field "MytextField"
put "" into wPreserve
put cr into last line of field "MytextField"
put endwPreserve into last line of field "MytextField"
put "" into endwPreserve
put the number of lines of ESLine into myESLength
split ESLine by cr
put myESLength into k
repeat with i = myESLength down to 1
put "-----SubDisplayEquation-----" & k into es
replace es with ESLine[i] in field "MytextField"
subtract 1 from k
end repeat
put the number of lines of ESuLine into myESuLength
split ESuLine by cr
put myESuLength into z
repeat with i = myESuLength down to 1
put "-----SDisplayEquation-----" & z into eSu
replace eSu with ESuLine[i] in field "MytextField"
subtract 1 from z
end repeat
put the number of lines of EELine into myEELength
split EELine by cr
put myEELength into n
repeat with i = myEELength down to 1
put "-----DisplayEquation-----" & n into eo
replace eo with EELine[i] in field "MytextField"
subtract 1 from n
end repeat
put the number of lines of EQLine into myEQLength
split EQLine by cr
put myEQLength into j
repeat with i = myEQLength down to 1
put "-----EqnarryDisplayEquation-----" & j into er
replace er with EQLine[i] in field "MytextField"
subtract 1 from j
end repeat
put the number of lines of EALine into myEALength
split EALine by cr
put myEALength into l
repeat with i = myEALength down to 1
put "-----AlignDisplayEquation-----" & l into ea
replace ea with EALine[i] in field "MytextField"
subtract 1 from l
end repeat
put the number of lines of TSLine into myTSLength
split TSLine by cr
put myTSLength into Ts
repeat with i = myTSLength down to 1
put "-----Table-----" & Ts into Tta
replace Tta with TSLine[i] in field "MytextField"
subtract 1 from Ts
end repeat
put the number of lines of stsLine into mystsLength
split stsLine by cr
put mystsLength into stab
repeat with i = mystsLength down to 1
put "-----_table_-----" & stab into sta
replace sta with stsLine[i] in field "MytextField"
subtract 1 from stab
end repeat
put the number of lines of ELine into myELength
split ELine by cr
put myELength into m
repeat with i = myELength down to 1
put "---In_Line_Equation---" & m into so
replace so with ELine[i] in field "MytextField"
subtract 1 from m
end repeat
replace "^EOL" with cr in field "MytextField"
replace "\$" with "{\XXdollarXX}" in field "MytextField"
end Restore
Is there any alternate way to do this?.
It looks like you're doing all the text replacement in a field. You should put the text content into a variable first, do all your replacing there, then put the variable's contents back into the field.

Vim: Replace n with n+1

How do I replace every number n that matches a certain pattern with n+1? E.g. I want to replace all numbers in a line that are in brackets with the value+1.
1 2 <3> 4 <5> 6 7 <8> <9> <10> 11 12
should become
1 2 <4> 4 <6> 6 7 <9> <10> <11> 11 12
%s/<\zs\d\+\ze>/\=(submatch(0)+1)/g
By way of explanation:
%s " replace command
"""""
< " prefix
\zs " start of the match
\d\+ " match numbers
\ze " end of the match
> " suffix
"""""
\= " replace the match part with the following expression
(
submatch(0) " the match part
+1 " add one
)
"""""
g " replace all numbers, not only the first one
Edit:
If you only want to replace in specific line, move your cursor on that line, and execute
s/<\zs\d\+\ze>/\=(submatch(0)+1)/g
or use
LINENUMs/<\zs\d\+\ze>/\=(submatch(0)+1)/g
(replace LINENUM with the actual line number, eg. 13)
In vim you can increment (decrement) the numeric digit on or after the cursor by pressing
NUMBER<ctrl-a> to add NUMBER to the digit
(NUMBER<ctrl-x> to substract NUMBER from the digit)
If only incrementing (decrementing) by one you don't need to specify NUMBER. In your case I would use a simple macro for this:
qaf<<ctrl-a>q
100<altgr-q>a
Here a brief explanation of the macro: It uses the find (f) commant to place the cursor on the opening < bracket. It is not necessary to position the cursor on the digit. When press the number on the cursor or the nearest number after the cursor will get incremented.
If you want an even shorter series of commands you can position your curser ONCE by pressing f<, increment the number with ctrl-a and then just repeatedly press ;.. The ; command repeats the last cursor movement i.e. the find command. The . command repeats the last text changing command.
Check out this link for further information or use the built in documentation: h: ctrl-a.

Resources