Skip to content

Commit

Permalink
Merge pull request #308 from gustaphe/undef
Browse files Browse the repository at this point in the history
Latexify undefined array elements
  • Loading branch information
gustaphe authored Oct 3, 2024
2 parents 16e29ef + 829832c commit c7ac169
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/latexarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ function _latexarray(
"}\n"
)

arr = latexraw.(arr; kwargs...)
for i in rows, j in columns
str *= arr[i,j]
if isassigned(arr, i, j)
str *= latexraw(arr[i,j]; kwargs...)
else
str *= raw"\cdot"
end
j == last(columns) ? (str *= eol) : (str *= " & ")
end

Expand Down
23 changes: 23 additions & 0 deletions test/latexarray_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,26 @@ tensor = rand(3,3,3)

tensor = fill(42)
@test_throws ErrorException("Cannot latexify n-dimensional tensors with n≠1,2") latexify(tensor)

undefarr = Array{Any,2}(undef, 2, 2)
@test latexify(undefarr) == replace(
raw"\begin{equation}
\left[
\begin{array}{cc}
\cdot & \cdot \\
\cdot & \cdot \\
\end{array}
\right]
\end{equation}
", "\r\n"=>"\n")
undefarr[1,1] = "x"
@test latexify(undefarr) == replace(
raw"\begin{equation}
\left[
\begin{array}{cc}
x & \cdot \\
\cdot & \cdot \\
\end{array}
\right]
\end{equation}
", "\r\n"=>"\n")

0 comments on commit c7ac169

Please sign in to comment.