From 5d87d3208715ec56189cd8afbecabb7d698cffae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler=20=28via=20gitlab=20runner=29?= Date: Wed, 27 Oct 2021 19:38:42 +0200 Subject: [PATCH] start working on vim script for equation array?, --- scripts/ieeeeqnarray.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/ieeeeqnarray.py diff --git a/scripts/ieeeeqnarray.py b/scripts/ieeeeqnarray.py new file mode 100644 index 0000000..c18a05f --- /dev/null +++ b/scripts/ieeeeqnarray.py @@ -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*}") +