Skip to content

Commit bd95c85

Browse files
feat: add latexify recipe for AnalysisPoint
1 parent 3986d82 commit bd95c85

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/systems/analysis_points.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ function Base.show(io::IO, ::MIME"text/plain", ap::AnalysisPoint)
140140
end
141141
end
142142

143+
@latexrecipe function f(ap::AnalysisPoint)
144+
index --> :subscript
145+
snakecase --> true
146+
ap.input === nothing && return 0
147+
outs = Expr(:vect)
148+
append!(outs.args, ap_var.(ap.outputs))
149+
return Expr(:call, :AnalysisPoint, ap_var(ap.input), ap.name, outs)
150+
end
151+
152+
function Base.show(io::IO, ::MIME"text/latex", ap::AnalysisPoint)
153+
print(io, latexify(ap))
154+
end
155+
143156
"""
144157
$(TYPEDSIGNATURES)
145158

test/latexify.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using Latexify
33
using ModelingToolkit
44
using ReferenceTests
55
using ModelingToolkit: t_nounits as t, D_nounits as D
6+
using ModelingToolkitStandardLibrary.Blocks
67

78
### Tips for generating latex tests:
89
### Latexify has an unexported macro:
@@ -47,3 +48,13 @@ eqs = [D(u[1]) ~ p[3] * (u[2] - u[1]),
4748
eqs = [D(x) ~ (1 + cos(t)) / (1 + 2 * x)]
4849

4950
@test_reference "latexify/40.tex" latexify(eqs)
51+
52+
@named P = FirstOrder(k = 1, T = 1)
53+
@named C = Gain(; k = -1)
54+
55+
ap = AnalysisPoint(:plant_input)
56+
eqs = [connect(P.output, C.input)
57+
connect(C.output, ap, P.input)]
58+
sys_ap = ODESystem(eqs, t, systems = [P, C], name = :hej)
59+
60+
@test_reference "latexify/50.tex" latexify(sys_ap)

test/latexify/50.tex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
\begin{equation}
2+
\left[
3+
\begin{array}{c}
4+
\mathrm{connect}\left( P_{+}output, C_{+}input \right) \\
5+
AnalysisPoint\left( \mathtt{C.output.u}\left( t \right), plant\_input, \left[
6+
\begin{array}{c}
7+
\mathtt{P.input.u}\left( t \right) \\
8+
\end{array}
9+
\right] \right) \\
10+
\mathtt{P.u}\left( t \right) = \mathtt{P.input.u}\left( t \right) \\
11+
\mathtt{P.y}\left( t \right) = \mathtt{P.output.u}\left( t \right) \\
12+
\mathtt{P.y}\left( t \right) = \mathtt{P.x}\left( t \right) \\
13+
\frac{\mathrm{d} \mathtt{P.x}\left( t \right)}{\mathrm{d}t} = \frac{ - \mathtt{P.x}\left( t \right) + \mathtt{P.k} \mathtt{P.u}\left( t \right)}{\mathtt{P.T}} \\
14+
\mathtt{C.u}\left( t \right) = \mathtt{C.input.u}\left( t \right) \\
15+
\mathtt{C.y}\left( t \right) = \mathtt{C.output.u}\left( t \right) \\
16+
\mathtt{C.y}\left( t \right) = \mathtt{C.k} \mathtt{C.u}\left( t \right) \\
17+
\end{array}
18+
\right]
19+
\end{equation}

0 commit comments

Comments
 (0)