Advertisement
Guest User

LaTeX matrices creator

a guest
Jan 18th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. #!/bin/python3
  2.  
  3. # --- Constants ---
  4. mtypes = ['b','v','p', '']
  5.  
  6. # --- Code ----
  7.  
  8. while True:
  9.     print("Select matrix type:\n1. bmatrix\t2. vmatrix\t3. pmatrix\t4. matrix\n")
  10.     stype = input('> ')
  11.    
  12.     try:
  13.         stype = int(stype)
  14.         if stype > 4 or stype < 1:
  15.             print("Please input a number from 1 to 4\n")
  16.             continue
  17.     except:
  18.         print("Please input a number from 1 to 4\n")
  19.         continue
  20.     break
  21.  
  22. stype = mtypes[stype - 1]
  23.  
  24. while True:
  25.     print ("\nInput the amount of matrix lines")
  26.  
  27.     try:
  28.         lines = int(input('> '))
  29.         if lines < 1:
  30.             print("Please input a positive number\n")
  31.             continue
  32.     except:
  33.         print("Please input a positive number\n")
  34.         continue
  35.     break
  36.  
  37. while True:
  38.     print ("\nInput the amount of matrix columns")
  39.  
  40.     try:
  41.         columns = int(input('> '))
  42.         if columns < 1:
  43.             print("Please input a positive number\n")
  44.             continue
  45.     except:
  46.         print("Please input a positive number\n")
  47.         continue
  48.     break
  49.  
  50. latex = "\\begin{" + stype + "matrix} "
  51.  
  52. print("Iteration started. Input the correspondent LaTeX of the elements for each line:")
  53. for i in range(0, lines):
  54.     print("Line " + str(i+1) + ":")
  55.     for j in range(0, columns):
  56.         print("\tElement " + str(j+1) + ": ", end="")
  57.         element = input()
  58.         latex += element
  59.         if j != columns-1:
  60.             latex += " & "
  61.         print("\n")
  62.  
  63.     if i != lines-1:
  64.         latex += " \\\\ "
  65.     print("\n\n")
  66.  
  67. latex += " \\end{" + stype + "matrix}"
  68.  
  69. print("Process ended. LaTeX: " + latex)
  70. input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement