ILIAS  release_8 Revision v8.24
class.ilMathJaxConfig.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 private const MATHJAX2_DEFAULT_URL = 'https://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML,Safe';
27 private const MATHJAX3_RELATIVE_URL = 'Services/MathJax/js/cdn-mathjax3-es5-tex-mml-chtml-safe.js';
28
29 private const LIMITER_MATHJAX = 0;
30 private const LIMITER_TEX = 1;
31 private const LIMITER_SPAN = 2;
32
33 protected bool $client_enabled;
34 protected string $client_polyfill_url;
35 protected string $client_script_url;
36 protected int $client_limiter;
37 protected bool $server_enabled;
38 protected string $server_address;
39 protected int $server_timeout;
40 protected bool $server_for_browser;
41 protected bool $server_for_export;
42 protected bool $server_for_pdf;
43
47 public function __construct(
48 bool $client_enabled,
50 string $client_script_url,
52 bool $server_enabled,
53 string $server_address,
58 ) {
59 $this->client_enabled = $client_enabled;
60 $this->client_polyfill_url = trim($client_polyfill_url);
61 $this->client_script_url = trim($client_script_url);
62 $this->client_limiter = (in_array(
64 [self::LIMITER_MATHJAX, self::LIMITER_TEX, self::LIMITER_SPAN]
66 $this->server_enabled = $server_enabled;
67 $this->server_address = trim($server_address);
68 $this->server_timeout = (empty($server_timeout) ? 5 : $server_timeout);
69 $this->server_for_browser = $server_for_browser;
70 $this->server_for_export = $server_for_export;
71 $this->server_for_pdf = $server_for_pdf;
72 }
73
77 public function getMathJax2DefaultUrl(): string
78 {
80 }
81
85 public function getMathJax3DefaultUrl(): string
86 {
87 return ILIAS_HTTP_PATH . '/' . self::MATHJAX3_RELATIVE_URL;
88 }
89
90
94 public function isClientEnabled(): bool
95 {
97 }
98
102 public function getClintPolyfillUrl(): string
103 {
105 }
106
110 public function getClientScriptUrl(): string
111 {
113 }
114
118 public function getClientLimiter(): int
119 {
121 }
122
127 public function getClientLimiterOptions(): array
128 {
129 return [
130 self::LIMITER_MATHJAX => '\&#8203;(...\&#8203;)',
131 self::LIMITER_TEX => '[tex]...[/tex]',
132 self::LIMITER_SPAN => '&lt;span class="math"&gt;...&lt;/span&gt;'
133 ];
134 }
135
139 public function getClientLimiterStart(): string
140 {
141 switch ($this->client_limiter) {
143 return '[tex]';
145 return '<span class="math">';
147 default:
148 return '\‍(';
149 }
150 }
151
155 public function getClientLimiterEnd(): string
156 {
157 switch ($this->client_limiter) {
159 return '[/tex]';
161 return '</span>';
163 default:
164 return '\‍)';
165 }
166 }
167
171 public function isServerEnabled(): bool
172 {
174 }
175
179 public function getServerAddress(): string
180 {
182 }
183
187 public function getServerTimeout(): int
188 {
190 }
191
195 public function isServerForBrowser(): bool
196 {
198 }
199
203 public function isServerForExport(): bool
204 {
206 }
207
211 public function isServerForPdf(): bool
212 {
214 }
215
220 {
221 $clone = clone $this;
222 $clone->client_enabled = $client_enabled;
223 return $clone;
224 }
225
229 public function withClientPolyfillUrl(string $client_js_url): ilMathJaxConfig
230 {
231 $clone = clone $this;
232 $clone->client_polyfill_url = $client_js_url;
233 return $clone;
234 }
235
239 public function withClientScriptUrl(string $client_async_url): ilMathJaxConfig
240 {
241 $clone = clone $this;
242 $clone->client_script_url = $client_async_url;
243 return $clone;
244 }
245
250 {
251 $clone = clone $this;
252 $clone->client_limiter = $client_limiter;
253 return $clone;
254 }
255
260 {
261 $clone = clone $this;
262 $clone->server_enabled = $server_enabled;
263 return $clone;
264 }
265
270 {
271 $clone = clone $this;
272 $clone->server_address = $server_address;
273 return $clone;
274 }
275
280 {
281 $clone = clone $this;
282 $clone->server_timeout = $server_timeout;
283 return $clone;
284 }
285
290 {
291 $clone = clone $this;
292 $clone->server_for_browser = $server_for_browser;
293 return $clone;
294 }
295
300 {
301 $clone = clone $this;
302 $clone->server_for_export = $server_for_export;
303 return $clone;
304 }
305
310 {
311 $clone = clone $this;
312 $clone->server_for_pdf = $server_for_pdf;
313 return $clone;
314 }
315}
Global Mathjax configuration.
withServerEnabled(bool $server_enabled)
Enable a server side rendering engine configured and enabled.
withClientScriptUrl(string $client_async_url)
Set the url of Mathjax script to be embedded on the page (for MathJax 3)
getMathJax2DefaultUrl()
Get the default URL for including MathJax 2.
getClientLimiterOptions()
Get the avaliable options for the client limiters.
getClientLimiter()
Type of enclosing limiters for wich the embedded client-side Mathjax is configured.
withClientLimiter(int $client_limiter)
Set the type of enclosing limiters for wich the embedded client-side Mathjax is configured.
getServerTimeout()
timeout (s) to wait for the result of the rendering server
isServerForBrowser()
Should the server-side rendingeing be used for browser output.
withClientPolyfillUrl(string $client_js_url)
Set the url of a polyfill script neededby MathJax 3.
withServerAddress(string $server_address)
Set the url of the Mathjax server.
isServerForPdf()
Should the server-side rendingeing be used for PDF generation.
getClientLimiterStart()
Start limiter of Latex code which the client-side Mathjax searches for.
getServerAddress()
Url of Mathjax server.
withClientEnabled(bool $client_enabled)
Enable latex code bing rendered in the browser.
withServerTimeout(int $server_timeout)
Set the timeout (s) to wait for the result of the rendering server.
isServerEnabled()
Is a server side rendering engine configured and enabled.
withServerForPdf(bool $server_for_pdf)
Enable the server-side rendingeing for PDF generation.
isServerForExport()
Should the server-side rendingeing be used for HTML exports.
getClientScriptUrl()
Url of Mathjax script to be embedded with script tag on the page.
getClintPolyfillUrl()
Url of a javascript polyfill (needed by MathJax 3)
getMathJax3DefaultUrl()
Get the default URL for including MathJax 3.
withServerForBrowser(bool $server_for_browser)
Enable the server-side rendingeing for browser output.
__construct(bool $client_enabled, string $client_polyfill_url, string $client_script_url, int $client_limiter, bool $server_enabled, string $server_address, int $server_timeout, bool $server_for_browser, bool $server_for_export, bool $server_for_pdf)
Constructor.
getClientLimiterEnd()
End limiter of Latex code which the client-side Mathjax searches for.
isClientEnabled()
Should latex code be rendered in the browser.
withServerForExport(bool $server_for_export)
Enable the server-side rendingeing for HTML exports.