|
1 | 1 | \documentclass{ximera} |
| 2 | + |
| 3 | +\input{preamble_graph.tex} |
| 4 | + |
2 | 5 | \title{Examples from/for precalc} |
3 | 6 |
|
4 | 7 |
|
|
7 | 10 | \end{abstract} |
8 | 11 | \maketitle |
9 | 12 |
|
10 | | -%% Default \begin{tikzpicture} options |
11 | | -\tikzset{ |
12 | | - xmGraphTikz/.style={}, |
13 | | - panel/.style={}, |
14 | | -% xmDesmosWidth/.code 2 args={\def\xmDesmosWidth{#2}}, % sets a macro when applied |
15 | | -% xmDesmosWidth/.default=600, % pixels |
16 | | -% xmDesmosHeight/.code 2 args={\def\xmDesmosHeight{#2}}, % sets a macro when applied |
17 | | -% xmDesmosHeight/.default=300, % pixels |
18 | | - } |
19 | | - |
20 | | - %% Default \begin{axis} options |
21 | | -\pgfplotsset{ |
22 | | - xmGraphPlotAxis/.style={ |
23 | | - xlabel={$x$}, % x-axis label |
24 | | - ylabel={$y$}, % y-axis label |
25 | | - axis lines=middle, |
26 | | - axis equal image, |
27 | | - axis line style={->}, |
28 | | -% panel, |
29 | | - }, |
30 | | - panel/.code={\def\xmGraphShowPanel{true}}, % sets a macro when applied |
31 | | - % xmGraphShowDesmos/.code={\def\xmGraphShowDesmos{true}}, % sets a macro when applied |
32 | | - % % xmGraphShowDesmos/.default={true}, |
33 | | - % xmGraphNoDesmos/.code={\let\xmGraphShowDesmos\undefined}, |
34 | | - % % xmGraphShowDesmos, |
35 | | - xmGraphShowCommand/.code={\def\xmGraphShowCommand{true}}, % sets a macro when applied |
36 | | - % xmGraphShowTikZ/.code={\def\xmGraphShowTikZ{true}}, % sets a macro when applied |
37 | | - % xmGraphNoTikZ/.code={\let\xmGraphShowTikZ\undDefInEd}, % sets a macro when applied |
38 | | - xmDesmosWidth/.store in=\xmDesmosWidth, |
39 | | - xmDesmosWidth/.default=600px, |
40 | | - xmDesmosHeight/.store in=\xmDesmosHeight, |
41 | | - xmDesmosHeight/.default=300px, |
42 | | -} |
43 | | - |
44 | | -% \pgfkeys{ |
45 | | -% /pgfplots/xmGraphShowDesmos/.store in=\xmGraphShowDesmos, |
46 | | -% /pgfplots/xmGraphShowDesmos/.initial=false, % initial default |
47 | | -% /pgfplots/xmGraphShowDesmos/.default=true, % if used as 'xmGraphShowDesmos' -> true |
48 | | -% /pgfplots/xmGraphNoDesmos/.code={% explicit "off" |
49 | | -% \pgfkeyssetvalue{/pgfplots/xmGraphShowDesmos}{false}% |
50 | | -% }, |
51 | | -% } |
52 | | - |
53 | | -\def\xmGraphShowDesmos{true} % default NOT inside the style: DOES NOT WORK |
54 | | - |
55 | | -% \pgfplotsset{ |
56 | | -% % plot-level style |
57 | | -% xmGraphPlot/.style={ |
58 | | -% /pgfplots/.cd, % <- ensures keys are interpreted as pgfplots keys |
59 | | -% domain=-2:2, |
60 | | -% samples=50, |
61 | | -% thick, |
62 | | -% }, |
63 | | -% % axis-level style |
64 | | -% xmGraphPlotAxis/.style={ |
65 | | -% /pgfplots/.cd, |
66 | | -% xmin=-2.3, xmax=2.3, |
67 | | -% ymin=-1, ymax=4, |
68 | | -% axis equal image, |
69 | | -% axis lines=middle, |
70 | | -% axis line style=->, |
71 | | -% } |
72 | | -% } |
73 | | - |
74 | | -\ExplSyntaxOn |
75 | | - |
76 | | -% Helper function to process each item |
77 | | -%%% The 'multi'-part, with f(x),g(x,f(x), does NOT yet work ) |
78 | | -\cs_new_protected:Nn \__multiplot_get_function:n { |
79 | | - % Check if the item contains slashes (legend and/or options separator) |
80 | | - % IN 2025 ? \seq_set_split_with_nested:nnnN { / } { | | } { #1 } \l_tmpa_seq |
81 | | - \seq_set_split:Nnn \l_tmpa_seq { // } { #1 } |
82 | | - \int_case:nn { \seq_count:N \l_tmpa_seq } { |
83 | | - { 1 } { |
84 | | - % No legend, no options: just plot function |
85 | | - #1 |
86 | | - } |
87 | | - { 2 } { |
88 | | - \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl % function |
89 | | - \l_tmpa_tl |
90 | | - } |
91 | | - { 3 } { |
92 | | - \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl % function |
93 | | - \l_tmpa_tl |
94 | | - } |
95 | | - } |
96 | | -} |
97 | | - |
98 | | -\cs_new_protected:Nn \__multiplot_process:nn { |
99 | | - % Check if the item contains slashes (legend and/or options separator) |
100 | | - % IN 2025 ? \seq_set_split_with_nested:nnnN { / } { | | } { #1 } \l_tmpa_seq |
101 | | - \seq_set_split:Nnn \l_tmpa_seq { // } { #2 } |
102 | | - \int_case:nn { \seq_count:N \l_tmpa_seq } { |
103 | | - { 1 } { |
104 | | - % No legend, no options: just plot function |
105 | | - \addplot[xmGraphPlot, #1] { #2 }; |
106 | | - } |
107 | | - { 2 } { |
108 | | - % Has legend: plot function and add legend entry |
109 | | - \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl % function |
110 | | - \seq_pop_left:NN \l_tmpa_seq \l_tmpb_tl % legend |
111 | | - \addplot[xmGraphPlot, #1] { \l_tmpa_tl }; |
112 | | - % Only add legend if not empty |
113 | | - %\tl_if_empty:NF \l_tmpb_tl { |
114 | | - \addlegendentry{\l_tmpb_tl} |
115 | | - %} |
116 | | - } |
117 | | - { 3 } { |
118 | | - % Has legend and options: plot function with custom options |
119 | | - \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl % function |
120 | | - \seq_pop_left:NN \l_tmpa_seq \l_tmpb_tl % legend |
121 | | - \seq_pop_left:NN \l_tmpa_seq \l_tmpc_tl % options |
122 | | - \addplot[xmGraphPlot, #1, \l_tmpc_tl] { \l_tmpa_tl }; |
123 | | - % Only add legend if not empty |
124 | | - \tl_if_empty:NF \l_tmpb_tl { |
125 | | - \addlegendentry{\l_tmpb_tl} |
126 | | - } |
127 | | - } |
128 | | - } |
129 | | -} |
130 | | - |
131 | | -\cs_new_protected:Nn \xmultiplot:nn { |
132 | | - \clist_map_inline:nn { #2 } { |
133 | | - \__multiplot_process:nn { #1 } { ##1 } |
134 | | - } |
135 | | -} |
136 | | - |
137 | | -\NewDocumentCommand \xmGraphPlot { o m } { \xmultiplot:nn {#1} {#2} } |
138 | | -\NewDocumentCommand \xmGraphGetFunction { m } { \__multiplot_get_function:n {#1} } |
139 | | -\ProvideDocumentCommand \xmGraphLegend { m } {} |
140 | | -\ProvideDocumentCommand \xmGraphExtra { m } {} |
141 | | - |
142 | | -\ExplSyntaxOff |
143 | | - |
144 | | -\newcommand\GetKeyFromStyle[2]{% |
145 | | - \pgfkeys{/pgfplots/.cd,#1}% |
146 | | - \pgfkeysvalueof{/pgfplots/#2}% |
147 | | -} |
148 | | - |
149 | | -\newcommand\GetPGFplotsKeyFromStyle[2]{% |
150 | | - % #1 = style name |
151 | | - % #2 = key name |
152 | | - % Save current value (to restore if undefined) |
153 | | - \pgfkeys{/pgfplots/.cd,#1}% |
154 | | - \pgfkeys{/pgfplots/#1} % executes the style code |
155 | | - |
156 | | - \typeout{KEY #2 in #1} |
157 | | - |
158 | | - % Try global key first |
159 | | - \pgfkeysifdefined{/pgfplots/#2}{% |
160 | | - \pgfkeysvalueof{/pgfplots/#2}% |
161 | | - \typeout{KEY found: #2 in #1: \pgfkeysvalueof{/pgfplots/#2}} |
162 | | - }{% |
163 | | - % Try axis key |
164 | | - \pgfkeysifdefined{/pgfplots/axis/#2}{% |
165 | | - \pgfkeysvalueof{/pgfplots/axis/#2}% |
166 | | - \typeout{KEY found in axis: #2 in #1: \pgfkeysvalueof{/pgfplots/axis/#2}} |
167 | | - }{% |
168 | | - % Try dummy option |
169 | | - \pgfkeysifdefined{/mydymmyoption/#2}{% |
170 | | - \pgfkeysvalueof{/mydymmyoption/#2}% |
171 | | - \typeout{KEY found dummyoption: #2 in #1: \pgfkeysvalueof{/mydymmyoption/#2}} |
172 | | - } |
173 | | - { |
174 | | - % Key not found → return empty |
175 | | - \typeout{KEY not found: #2 in #1} |
176 | | - }% |
177 | | - }% |
178 | | - } |
179 | | -} |
180 | | - |
181 | | -\makeatletter |
182 | | -\renewcommand\GetPGFplotsKeyFromStyle[2]{% |
183 | | - % #1 = style name |
184 | | - % #2 = key name |
185 | | - \pgfkeys{/pgfplots/.cd,#1}% activate style |
186 | | - %\typeout{KEY #2 in #1} |
187 | | - \pgfkeysifdefined{/pgfplots/#2}{% |
188 | | - \pgfkeysvalueof{/pgfplots/#2}% |
189 | | - % \typeout{KEY found: #2 in #1: \pgfkeysvalueof{/pgfplots/#2}} |
190 | | - }{% |
191 | | - \pgfkeysifdefined{/pgfplots/axis/#2}{% |
192 | | - \pgfkeysvalueof{/pgfplots/axis/#2}% |
193 | | - %\typeout{KEY axis found: #2 in #1: \pgfkeysvalueof{/pgfplots/#2}} |
194 | | - }{% |
195 | | - %\pgfkeysifdefined{/pgfplots/.@cmd/#2}{TRUE}{FALSE}% |
196 | | - % undefined → return empty |
197 | | - }% |
198 | | - }% |
199 | | -} |
200 | | -\makeatother |
201 | | - |
202 | | -\makeatletter |
203 | | -% #1 = macro to store value |
204 | | -% #2 = style name |
205 | | -% #3 = key name |
206 | | -\newcommand\GetPGFplotsKeyFromStyleToMacro[3]{% |
207 | | - %\begingroup |
208 | | - \def#1{}% initialize macro to empty |
209 | | - \pgfkeys{/pgfplots/.cd,#2}% activate the style |
210 | | - % Try normal key |
211 | | - \pgfkeysifdefined{/pgfplots/#3}{% |
212 | | - \pgfkeysgetvalue{/pgfplots/#3}{#1}% |
213 | | - }{% |
214 | | - % Try axis key |
215 | | - \pgfkeysifdefined{/pgfplots/axis/#3}{% |
216 | | - \pgfkeysgetvalue{/pgfplots/axis/#3}{#1}% |
217 | | - }{% |
218 | | - % Key not found → leave empty |
219 | | - \def#1{}% |
220 | | - }% |
221 | | - }% |
222 | | - %\endgroup |
223 | | -} |
224 | | - |
225 | | -\makeatother |
226 | | - |
227 | | -\renewcommand{\graph}[2][]{ |
228 | | - \begingroup |
229 | | - \ifdefined\xmGraphShowDesmos % generic tikz-options confuse the pgfkeys ... |
230 | | - %\typeout{SETTING tmpstyle (\xmGraphShowDesmos\ for #1)} |
231 | | -\pgfplotsset{ %% The #1 will process the additional options, so that \xmGraphShowTikZ works !!! |
232 | | - tmpstyle/.style={ |
233 | | - /pgfplots/xmGraphPlot, % apply plot keys |
234 | | - /pgfplots/xmGraphPlotAxis, % apply axis keys |
235 | | - % /pgfplots/.cd, % ensure any extra keys are interpreted in pgfplots |
236 | | - #1 % allow overrides |
237 | | - } |
238 | | -} |
239 | | - \pgfkeys{/pgfplots/.cd,#1}% activate style |
240 | | -\else |
241 | | - %\typeout{SKIPPING tmpstyle for #1} |
242 | | -\fi |
243 | | - |
244 | | -\ifdefined\HCode |
245 | | - \HCode{<div class="xmdesmos">} |
246 | | -\else |
247 | | - \def\xmGraphShowTikZ{true} %% ALWAYS show TikZ in PDF !!! |
248 | | -\fi |
249 | | -
|
250 | | - \ifdefined\xmGraphShowCommand |
251 | | - \ifdefined\HCode |
252 | | - % \HCode{<h1> Command: \string\graph[#1]{#2} </h1> } |
253 | | - \else |
254 | | - % {\Large\bf With options #1 } |
255 | | - \fi |
256 | | - \fi |
257 | | -
|
258 | | -
|
259 | | -
|
260 | | -\ifdefined\HCode\ifdefined\xmGraphShowDesmos |
261 | | -% \pgfplotsset{ |
262 | | -% xxxxtmpstyle/.style = { |
263 | | -% /pgfplots/.append style={xmGraphPlot} % apply xmGraphPlot in axis context |
264 | | -% /pgfplots/axis/.append style={xmGraphPlotAxis} % apply xmGraphPlot in axis context |
265 | | -% /pgfplots/axis/.append style={#1} % apply xmGraphPlot in axis context |
266 | | -% }, |
267 | | -% } |
268 | | -
|
269 | | -
|
270 | | -
|
271 | | -% \GetPGFplotsKeyFromStyleToMacro{\myval}{tmpstyle}{axis equal image} |
272 | | -% axis equal image = \myval % prints "-2:2" |
273 | | -
|
274 | | -% \GetPGFplotsKeyFromStyleToMacro{\myval}{tmpstyle}{xlabel} |
275 | | -% xlabel = \myval % prints "-2:2" |
276 | | -% xlabel = \HCode{\myval} % prints "-2:2" |
277 | | -
|
278 | | -%\typeout{AXIS KEY: \GetPGFplotsKeyFromStyle{tmpstyle}{axis equal image}} |
279 | | -% AXIS : \GetPGFplotsKeyFromStyle{tmpstyle}{axis equal image} |
280 | | -% PANEL : \GetPGFplotsKeyFromStyle{tmpstyle}{panel} |
281 | | -% XLABEL : \GetPGFplotsKeyFromStyle{tmpstyle}{xlabel} |
282 | | -
|
283 | | - \HCode{<div class="desmos-placeholder" data-options="} |
284 | | - %%% still an issue with $x$ vs x (Desmos prints the $'s !) |
285 | | - % \GetPGFplotsKeyFromStyleToMacro{\myval}{tmpstyle}{xlabel} |
286 | | - % xlabel=\HCode{\myval}, |
287 | | - % \GetPGFplotsKeyFromStyleToMacro{\myval}{tmpstyle}{ylabel} |
288 | | - % ylabel=\HCode{\myval}, |
289 | | - % ylabel=\HCode{\GetPGFplotsKeyFromStyle{tmpstyle}{ylabel}}, |
290 | | - xmax=\GetPGFplotsKeyFromStyle{tmpstyle}{xmax}, |
291 | | - xmin=\GetPGFplotsKeyFromStyle{tmpstyle}{xmin}, |
292 | | - ymin=\GetPGFplotsKeyFromStyle{tmpstyle}{ymin}, |
293 | | - ymax=\GetPGFplotsKeyFromStyle{tmpstyle}{ymax}, |
294 | | - \ifdefined\xmGraphShowPanel panel=true, \fi |
295 | | - \ifdefined\xmDesmosWidth xmDesmosWidth=\xmDesmosWidth, \fi |
296 | | - \ifdefined\xmDesmosHeight xmDesmosHeight=\xmDesmosHeight, \fi |
297 | | - \if\relax\detokenize\expandafter{\GetPGFplotsKeyFromStyle{tmpstyle}{axis equal image}}\relax |
298 | | - axis equal image=true, |
299 | | - \fi |
300 | | - \HCode{" data-graph='}\detokenize{#2}\HCode{'"></div>}% |
301 | | -\fi\fi% |
302 | | -\ifdefined\xmGraphShowTikZ% |
303 | | - \begin{tikzpicture}[xmGraphTikz] |
304 | | - \begin{axis}[xmGraphPlotAxis,#1] |
305 | | - \xmGraphPlot[]{#2} |
306 | | - % \xmGraphPlot[#1]{#2} |
307 | | - \xmGraphLegend{} |
308 | | - \xmGraphExtra{} |
309 | | - \end{axis} |
310 | | - \end{tikzpicture} |
311 | | -\fi |
312 | | -
|
313 | | -\endgroup |
314 | | -} |
315 | | -
|
316 | | -\ExplSyntaxOn |
317 | | -\bool_set_true:N \l__trace_errors_bool |
318 | | -\ExplSyntaxOff |
319 | | -
|
320 | | -\NewDocumentCommand{\xmgraph}{ O{} m } |
321 | | -{ |
322 | | - % #1 = optional key-value options |
323 | | - % #2 = the math expression (can include \frac, \sqrt, etc.) |
324 | | - |
325 | | - % Store argument verbatim |
326 | | - \tl_set:Nn \l_tmpa_tl {#2} |
327 | | -
|
328 | | - % Expand token list at use, safely passing to \graph |
329 | | - \exp_args:No \graph [#1] {\l_tmpa_tl} |
330 | | -} |
331 | | -
|
332 | | -\ExplSyntaxOff |
333 | | -
|
334 | | -% \newcommand{\xmgraph}[2][]{$\graph{#2}$} |
335 | | -\pgfplotsset{ |
336 | | - xmGraphPlot/.append style={ |
337 | | - domain=-2:2, |
338 | | - }, |
339 | | - % Axis-only keys go in a separate style |
340 | | - xmGraphPlotAxis/.append style={ |
341 | | - xmin=-2.3, |
342 | | - xmax=2.3, |
343 | | - ymin=-1, ymax=4, |
344 | | - % xmDesmosWidth=500px, |
345 | | - % xmDesmosHeight=500px, |
346 | | - % ymin, ymax, tick settings etc. |
347 | | - } |
348 | | - } |
349 | | -
|
350 | | -
|
351 | | -% xmax=\GetPGFplotsKeyFromStyle{xmGraphPlot}{xmax} |
352 | | -
|
353 | | -% xmax=\GetPGFplotsKeyFromStyle{xmGraphPlotAxis}{xmax} |
354 | | -% \graph{x^2/2//function//blue} |
355 | | -
|
356 | 13 |
|
357 | 14 | \def\xmGraphShowCommand{true} |
358 | 15 |
|
|
368 | 25 | xmin=-2.3, |
369 | 26 | xmax=2.3, |
370 | 27 | ymin=-1, ymax=4, |
371 | | - xmDesmosWidth =200px, |
372 | | - xmDesmosHeight=200px, |
| 28 | + xmDesmosWidth =800px, |
| 29 | + xmDesmosHeight=800px, |
373 | 30 | % ymin, ymax, tick settings etc. |
374 | 31 | } |
375 | 32 | } |
|
0 commit comments