start working on vim script for equation array?,
This commit is contained in:
parent
e575d61c2b
commit
5d87d32087
1 changed files with 29 additions and 0 deletions
29
scripts/ieeeeqnarray.py
Normal file
29
scripts/ieeeeqnarray.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# A python script designed to parse the contents of an \[ \] in latex (given in the arguments), and make a nice IEEEeqnarray* with correct indent and columns from it.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
indent=len(sys.argv[1])-4 # Indent got by the indent of the leading \[ of equation
|
||||||
|
topline = sys.argv[2].strip() # Get the content of the first line of the equation
|
||||||
|
level = 0 # Counts the 'level' of stacked braces
|
||||||
|
position = 0 # Will save the position of the found = in the top line
|
||||||
|
parsed_line = '' # Parsed top line
|
||||||
|
|
||||||
|
for x in topline:
|
||||||
|
if x in ['(','[','{']:
|
||||||
|
level+=1
|
||||||
|
parsed_line+=x
|
||||||
|
elif x in [')',']','}']:
|
||||||
|
level-=1
|
||||||
|
parsed_line+=x
|
||||||
|
elif level == 0 and x == '=':
|
||||||
|
position = len(parsed_line)
|
||||||
|
parsed_line+='& = &'
|
||||||
|
else:
|
||||||
|
parsed_line+=x
|
||||||
|
|
||||||
|
# Set correct indent and newline to the parsed line
|
||||||
|
parsed_line = ' '*(indent+4) + parsed_line[0:-1].strip() + ' \\\\\n'
|
||||||
|
|
||||||
|
# Print the output, adding \begin{}, the top line, a new line with '& = &' and \end{}
|
||||||
|
print(" "*indent +"\\begin{IEEEeqnarray*}{rCl}\n" + parsed_line + ' '*(position+indent+4) + "& = & \n" + " "*indent + "\\end{IEEEeqnarray*}")
|
||||||
|
|
Loading…
Reference in a new issue