Skip to content

Commit

Permalink
formatting in latex for dot_pro
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulranjansah committed Jun 23, 2024
1 parent a51f4a0 commit 9fc7c40
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def dot_product_matrix(self):
Dot product of n numbers of a*b matrix with proper dimension
Latex based output with intermediate steps and final solution
"""
vertical_spacer = 0
initial_matrix = self.builder.matrices
matrix_list = []

Expand All @@ -150,15 +151,15 @@ def dot_product_matrix(self):

with open("main_out.tex", "a", encoding="utf-8") as output_file:
for matrices in matrix_list:
output_file.write("$" + latex(matrices) + "$")
output_file.write("\n" + "\\hspace{0.5cm}")
output_file.write("$" + latex(matrices) + "$\n")
output_file.write("\n" + "\\vspace{0.5cm}" + "\n")

# Iterate through the matrices, stopping before the last one since we're looking ahead by one matrix
for idx in range(matrix_participants - 1):
rightmost_matrix = matrix_list.pop()
rightmost_matrix_transpose = rightmost_matrix.T # Transpose the current matrix to work with its rows
_, symbol_count = rightmost_matrix_transpose.shape
i = 0
formatting_hor = 0
next_matrix = matrix_list.pop() # The next matrix to the left

for row in rightmost_matrix_transpose.tolist(): # Convert each row of the transposed matrix to a list
Expand All @@ -169,14 +170,19 @@ def dot_product_matrix(self):
dot_product_step = f"{latex(element)}{latex(next_matrix.col(column))}"
row_steps.append(dot_product_step)

i += 1
if i % symbol_count != 0:
formatting_hor += 1
vertical_spacer += 1
if formatting_hor % symbol_count != 0:
row_steps.append("+")
else:
row_steps.append("\\hspace{0.5cm}")

steps.append("".join(row_steps))

if vertical_spacer % 4 == 0:
steps.append("\\vspace{0.5cm}" + "\n")


output = rightmost_matrix * next_matrix
# output = simplify(output)

Expand All @@ -188,7 +194,10 @@ def dot_product_matrix(self):
# Write these steps to a file
with open("main_out.tex", "a", encoding="utf-8") as output_file:
for step in steps:
output_file.write("$" + step + "$" + "\n")
if step.strip() == "\\vspace{0.5cm}":
output_file.write(step + "\n")
else:
output_file.write("$" + step + "$" + "\n")

output_file.write("$" + latex(output) + "$")

Expand Down

0 comments on commit 9fc7c40

Please sign in to comment.