Debian Codegraph @

texmf-dist/doc/latex/tensorstyles/tensorstyles-doc.tex

raw
1 \documentclass{l3doc}
2 \usepackage[T1]{fontenc}
3 \usepackage{pdfpages}
4 \usepackage{standalone}
5 \usepackage{tensorstyles}
6 % \usepackage{readprov}
7 % \ReadPackageInfos{tensorstyles}
8 \edef\tensorstylesVersion{v1.0.1.4} %{\fileversion}
9 \edef\tensorstylesDate{2026-04-28} %{\filedate}
10
11 \usepackage{parskip}
12 \usepackage{setspace}
13 \usepackage{xspace}
14 \onehalfspacing
15
16 \usepackage{xcolor}
17 \definecolor{tPrim}{HTML}{00707F} % Green-Blue
18 \definecolor{tSec}{HTML}{5FA4B0} % Green-Blue light
19 \definecolor{tAccent}{HTML}{F07F3C} % Orange
20 \definecolor{tGrey}{HTML}{E6E6E1} % Grey-Beige
21
22 % \usepackage{fancyvrb}
23 \usepackage{listings}
24 \lstset{
25 language=[LaTeX]{TeX},
26 basicstyle=\ttfamily,
27 keywordstyle=\color{tPrim}\bfseries,
28 commentstyle=\color{tSec},
29 stringstyle=\color{tSec},
30 backgroundcolor=\color{white},
31 numbers=none,
32 numberstyle=\tiny\ttfamily,
33 stepnumber=2,
34 showspaces=false,
35 showstringspaces=false,
36 showtabs=false,
37 frame=none,
38 framerule=1pt,
39 tabsize=2,
40 rulesep=5em,
41 captionpos=b,
42 breaklines=true,
43 breakatwhitespace=false,
44 framexleftmargin=0em,
45 framexrightmargin=0em,
46 xleftmargin=0em,
47 xrightmargin=0em,
48 aboveskip=1em,
49 belowskip=1em,
50 morekeywords={plain,tensorsset},
51 }
52 \lstMakeShortInline|
53
54 \usepackage{hyperref}
55
56 \setlength{\fboxsep}{0pt}%
57 \usepackage{subcaption} % For subfigures
58 \usepackage{cleveref} % for references
59
60 \providecommand{\defopt}[1]{\underline{#1}}%{default: #1}%
61 \NewDocumentEnvironment{DescribetensorstylesOption}{ o m m m }{
62 % At beginning of the environment
63 \DescribeOption{#2} % from l3doc
64 \IfNoValueTF{#1}{
65 % true => left empty intentionally
66 }{
67 %false
68 \DescribeOption{
69 % add extra info like added or updated dates to mimic 'function' env.
70 \rule[2.5ex]{\linewidth}{0.3pt}
71 \\[-3.5ex]
72 {\scriptsize #1 \hfill\ }
73 }
74 }
75 \begin{minipage}[t]{\textwidth}
76 \textit{\textbf{\textcolor{tSec}{#3}}}\dotfill\,\defopt{#4}\par
77 \begingroup
78 \vspace{0.5em}
79 }{
80 % At environment's end
81 \par
82 \endgroup
83 \end{minipage}
84 }
85
86
87 %% =====================================================================
88 \title{\textsc{tensorstyles}\\ A package to provide generic customizable displays of tensors (including vector, matrix, etc.) separating them from their forms.}
89 \author{Romain NOEL \\ \url{[email protected]}}
90 \date{\tensorstylesVersion~---~\tensorstylesDate}
91
92 \providecommand{\pkgName}{\textbf{\textsc{tensorstyles}}\xspace}
93
94 %% =====================================================================
95
96
97 \begin{document}
98 \maketitle
99
100 \begin{abstract}
101 They are different notation conventions for tensors.
102 And according to the context (or the local rules) one would like to switch between conventions: keeping the meaning of each tensor, just changing the display.
103 So, this package is here to print tensors according to their order yet independently from their meaning in a very customizable way.
104 \end{abstract}
105
106 \tableofcontents
107
108
109 %% ------------------------------------
110 \section{Introduction}
111 \pkgName was created to solve a problem we regularly faced: switching from one tensor notation to another.
112 Such an action should be trivial but mainstream tensors libraries do not separate content and form, and only offer one or two notations each.
113
114 Therefore, if a user wants to switch from one convention to another (let's say when publish in several journals), they will need to manually change all the command related to tensor by hand without changing the content of their documents.
115
116 This is why we propose \pkgName, a package that allows the representation of tensors in many notations, and to switch between them seamlessly.
117
118 %% ------------------------------------
119 \section{Getting started}
120 \subsection{Installing from CTAN}
121 The latest stable version of \pkgName is available on
122 \href{https://ctan.org/pkg/tensorstyles}{CTAN}
123 and should now be part of the usual \TeX\ distributions (\TeX\ Live, Mac\TeX\ , Mik\TeX\ ), under the name
124 \textit{\pkgName}.
125 It means that if your distribution is kept up-to-date, the package should normally be already installed on your system.
126 If this is not the case, consider updating the packages of your Tex distribution.
127
128 For \TeX\ Live and Mac\TeX\ users, this usually means running
129 \begin{lstlisting}
130 tlmgr update --all
131 \end{lstlisting}
132 or if administrative privileges are required
133 \begin{lstlisting}
134 sudo tlmgr update --all
135 \end{lstlisting}
136
137 For Mik\TeX\ users, please refer to \href{https://miktex.org/howto/update-miktex}{the official Mik\TeX\ documentation}.
138
139
140 \subsection{Installing from Gitlab}
141 If you want to use the cutting-edge development version of \pkgName, you can install it manually by following these steps:
142 \begin{description}
143 \item[Download the source] from
144 \href{https://gitlab.com/RomainNOEL/tensorstyles}{\pkgName repository}
145 using |git clone| or as a
146 \href{https://gitlab.com/RomainNOEL/tensorstyles/-/archive/master/tensorstyles-master.zip}{zip archive}
147 of the latest development version.
148 \item[Compile the style files] by running |l3build unpack| inside the downloaded directory.
149 (Or run \LaTeX{} directly on |source/tensorstyles.ins|.)
150 \item[Move the resulting |*.sty| files] to the folder containing your presentation.
151 To use \pkgName with many presentations, run
152 |l3build install| or move the |*.sty| files to a folder in your \TeX{} path instead.
153 \item[Use the package] by declaring \lstinline|\usepackage{tensorstyles}| in the preamble of your document.
154 \end{description}
155
156 \pkgName uses the l3build system to offer the following installation options for advanced users:
157 \begin{description}
158 \item[|l3build unpack|] builds the theme style files.
159 \item[|l3build doc|] builds this documentation manual and the examples.
160 \item[|l3build check|] builds the theme and manual.
161 \item[|l3build clean|] removes the files generated by |l3build|.
162 \item[|l3build install|] installs the theme into your local texmf folder.
163 \item[|l3build uninstall|] removes the theme from your local texmf folder.
164 \end{description}
165
166
167 % \subsection{Overleaf}
168 % \pkgName is therefore automatically supported for new documents.
169 % If you want to switch older documents to use the \pkgName theme, you need to \href{https://www.overleaf.com/blog/new-feature-select-your-tex-live-compiler-version}{select
170 % TexLive 2021 or higher as your TeX Live version} (this may cause issues with other packages used in your presentation).
171
172 % In addition to that, a template project was created and is publicly available in the \href{https://www.overleaf.com/latex/templates/demopkg/wjyyzvdzqkgf}{Overleaf Gallery} to bootstrap your presentation.
173
174
175 %% ------------------------------------
176 \subsection{A minimal example}
177 The following code shows a minimal example \pkgName usage
178 % , and the output generated is given on \cref{fig-minimal}
179 .
180
181 \begin{lstlisting}
182 \documentclass{article}
183 \usepackage{tensorstyles}
184 \begin{document}
185 $\tensor[preset=einstein]{4}{A}$
186 \end{document}
187 \end{lstlisting}
188
189 \begin{figure}[htp]
190 \centering
191 {$\tensor[preset=einstein]{4}{A}$}
192 \caption{Result of a simple example.}
193 \label{fig-minimal}
194 \end{figure}
195
196
197 \subsection{Dependencies}
198 \pkgName depends on the following standard packages:
199 \begin{itemize}
200 \item |expl3|
201 \item |amsmath|
202 \item |amssymb|
203 \item |mathtools|
204 \end{itemize}
205
206
207 \section{Creating and using commands}
208 \subsection{Creating a command}
209 The \pkgName package does not only provide a macro to create tensors.
210 The users can create their own.
211
212 To do so the package provides a command that acts in a manner similar to a constructor in object-oriented programming; this command is \texttt{\textbackslash DeclaretensorstylesCmd}
213
214 It takes two arguments, the first is the name of the macro to create, including the backslash, and the second, optional argument, is a list of options to customize the display.
215
216 For example:
217 \begin{lstlisting}
218 \DeclareTensorsCmd{\myTensorCmd}[preset=einstein]
219 \DeclareTensorsCmd{\myOtherTensorCmd}[preset=math, arrows=true]
220 \DeclareTensorsCmd{\thatTensorCmd}[preset=einstein, default-indices=contra]
221 \DeclareTensorsCmd{\anotherTensorCmd}[preset=full]
222 \end{lstlisting}
223
224 Afterward the newly created command can be used.
225
226
227 \subsection{Using a custom command}\label{sec:customCom}
228 Once a command is created it can be used anywhere in the document afterward.
229 All the commands take the same arguments.
230
231 \begin{function}{\tensor[<option>]{<rank>}{<symbol>}[<indices>]_{sub}^{sup}}
232 or |\myTensorCmd[<option>]{<rank>}{<symbol>}[<indices>]_{sub}^{sup}|
233 \begin{arguments}
234 \item |options|: an optional list of options to override for this call
235 \item |rank|: the rank of the tensor
236 \item |symbol|: the symbol that represents the tensor
237 \item |indices|: an optional list of Einstein indices
238 \item |sub| and |sup|: optional sub- and super-scripts to add after the tensor
239 \end{arguments}
240 The options argument accepts any and all of the options that can be defined during command creation.
241 The options given will override the ones that were defined when the command was created, but only for this call.
242
243 The rank can be a number or a letter.
244 It is used for determining the font to use, which arrow type to add, and how many indices to write.
245 For fonts and arrows, this is determined by a list, customizable via an option, that associates a given rank with a font and an arrow.
246 For indices, unless they were manually given, the macro will add as many indices as the rank specified if it is a number, or if it is a letter the rank itself will be added instead.
247 There is one exception to this: x and X.
248 When used, the macro will calculate the rank based on the number of indices given, potentially 0.
249
250 The symbol can be anything, including another tensor; it is the object to which the notations will be added.
251
252 Indices are given with a specific syntax:
253 \begin{itemize}
254 \item First, write either \^{} for contravariant indices or \_ for covariant indices.
255 \item Then any character that follows will be added as an index; for instance \^{}abc adds three contravariant indices a, b, and c.
256 \item Any subsequent \^{} and \_ is used to switch between covariant and contravariant indices.
257 \item If a group, \{...\}, is given it is treated as one index and it is expanded, allowing indices to be given with sub- and superscripts, or even passing a tensor as an index.
258 \end{itemize}
259
260 Every created command also has a star variant.
261 This variant has another, fully customizable, set of options.
262 This allows one to rapidly switch between two conventions.
263 \end{function}
264
265
266 %% ------------------------------------
267 \section{Options}
268 All the options have a star version used for the star variant of the command.
269 They take the same arguments and have the same effects.
270 Their name is the name of the regular options with a star added at the end.
271 For example, \texttt{preset} and \texttt{preset*}.
272
273 The default values of each option depend on the preset.
274
275
276 \subsection{Local vs. global options}
277 The options given directly to the command (as described in the section \ref{sec:customCom}) are applied locally.
278 So they will only affect the display of this particular command, not the following ones.
279
280 For global setting that will last until the next modification, one can use
281 \begin{function}{\tensorsseet{<command>}[<global options>]}
282 \begin{arguments}
283 \item |command| for which the options have to be set.
284 \item |global options| that will be set.
285 \end{arguments}
286 This setting can be called at any moment within the document.
287 \end{function}
288
289
290 \subsection{General options}
291 \DescribeOption{preset}
292 \begin{DescribetensorstylesOption}{}
293 {empty, full, math, arrow, einstein, engineer, bra, ket}{full}
294 Which preset to use.
295
296 |\tensor[preset=empty]{2}{x}| gives $\tensor[preset=empty]{2}{x}$
297 \\
298 |\tensor[preset=full]{2}{x}| gives $\tensor[preset=full]{2}{x}$
299 \\
300 |\tensor[preset=math]{2}{x}| gives $\tensor[preset=math]{2}{x}$
301 \\
302 |\tensor[preset=arrow]{2}{x}| gives $\tensor[preset=arrow]{2}{x}$
303 \\
304 |\tensor[preset=einstein]{2}{x}| gives $\tensor[preset=einstein]{2}{x}$
305 \\
306 |\tensor[preset=engineer]{2}{x}| gives $\tensor[preset=engineer]{2}{x}$
307 \\
308 |\tensor[preset=bra]{2}{x}| gives $\tensor[preset=bra]{2}{x}$
309 \\
310 |\tensor[preset=ket]{2}{x}| gives $\tensor[preset=ket]{2}{x}$
311 \vspace{2em}
312 \end{DescribetensorstylesOption}
313
314 \DescribeOption{switch-*}
315 \begin{DescribetensorstylesOption}{}
316 {true, false}{false}
317 Option to invert the star switch and regular version.
318 |\tensor*{2}{x}| is equivalent to |\tensor[switch-*=true]{2}{x}|.
319
320 Every option has a star equivalent that controls the display of the star-versioned command.
321 Therefore, one can use a combination of |preset| and |preset*| to switch easily between two displays.
322
323 For example, with the global setup: |\tensorsset{\tensor}[preset=math, preset*=einstein]|,
324 the commands |$\tensor{2}{x}$|, |$\tensor[switch-*=true]{2}{x}$| and |$\tensor*{2}{x}$|
325 yields : \tensorsset{\tensor}[preset=math, preset*=einstein] $\tensor{2}{x}$, $\tensor[switch-*=true]{2}{x}$ and $\tensor*{2}{x}$
326
327 \vspace{2em}
328 \end{DescribetensorstylesOption}
329
330 % \DescribeOption{style-var}
331 % \begin{DescribetensorstylesOption}{}
332 % {math, einstein, ...}{}
333 % This option is informative; it describes the convention being used.
334 % \vspace{2em}
335 % \end{DescribetensorstylesOption}
336
337
338 \subsection{Font options}
339 \DescribeOption{font}
340 \begin{DescribetensorstylesOption}{}
341 {true, false}{true}
342 Whether a special font should be applied to tensors.
343 \vspace{2em}
344 \end{DescribetensorstylesOption}
345
346 \DescribeOption{font-cmd}
347 \begin{DescribetensorstylesOption}{}
348 {\{0=\textbackslash font, 1=\textbackslash font, ...\}}{}
349 A list containing pairs \texttt{rank=font}.
350 It contains the fonts that will be used for a tensor of a given rank.
351 If the user tries to create a tensor with a rank not defined here and font is activated, the package will throw an error.
352
353 For example,
354 |font-cmd = {0={}, 1=\boldsymbol, 2=\MakeUppercase,| |3=\MakeUpperCal, 4=\MakeUpperBB, 5=\MakeBoldUppercase, n=\mathfrak}| is used for |preset=math|
355 \vspace{2em}
356 \end{DescribetensorstylesOption}
357
358
359 \subsection{Arrows options}
360 \DescribeOption{arrows}
361 \begin{DescribetensorstylesOption}{}
362 {true, false}{true}
363 Whether arrows should be added to tensors.
364 \vspace{2em}
365 \end{DescribetensorstylesOption}
366
367 \DescribeOption{arrow-cmd}
368 \begin{DescribetensorstylesOption}{}
369 {\{0=\textbackslash macro, 1=\textbackslash macro, ...\}}{}
370 A list containing pairs \texttt{rank=macro}.
371 It contains the macro that will be used to add arrows for a tensor of a given rank.
372 If the user tries to create a tensor with a rank not defined here and arrows are activated, the package will throw an error.
373
374 For example, |arrow-cmd = {0={}, 1=\overrightarrow, 2=\overleftrightarrow,| |3=\overrightleftrightarrow, 4=\overdoubleleftrightarrow,| |5=\overrightdoubleleftrightarrow, n=\underleftrightarrow}| is used for |preset=arrow|
375 \vspace{2em}
376 \end{DescribetensorstylesOption}
377
378 \DescribeOption{recursive-arrows}
379 \begin{DescribetensorstylesOption}{}
380 {true, false}{false}
381 Whether to add as many arrows as the rank.
382 \vspace{2em}
383 \end{DescribetensorstylesOption}
384
385 \DescribeOption{recursive-arrows-cmd}
386 \begin{DescribetensorstylesOption}{}
387 {\textbackslash macro}{}
388 The macro that will be used to add arrows recursively, for example |recursive-arrows-cmd=\underline| is use for |preset=engineer|.
389 \vspace{2em}
390 \end{DescribetensorstylesOption}
391
392
393 \subsection{Einstein options}
394 \DescribeOption{contra-variant}
395 \begin{DescribetensorstylesOption}{}
396 {true, false}{true}
397 Whether indices should be added to tensors.
398 \vspace{2em}
399 \end{DescribetensorstylesOption}
400
401 \DescribeOption{default-indices}
402 \begin{DescribetensorstylesOption}{}
403 {contra, covariant}{covariant}
404 Whether indices added automatically should be covariant or contravariant.
405
406 For example: |\tensor[default-indices=contra]{2}{x}| gives
407 $\tensor[default-indices=contra]{2}{x}$
408 \vspace{2em}
409 \end{DescribetensorstylesOption}
410
411 \DescribeOption{contra-style}
412 \begin{DescribetensorstylesOption}{}
413 {greek, alph, arabic}{alph}
414 The alphabet to use when adding contravariant indices automatically.
415 Either Greek or Latin alphabets, or numbers.
416
417 For example: |\tensor[contra-style=arabic,default-indices=contra]{2}{x}| gives
418 $\tensor[contra-style=arabic,default-indices=contra]{2}{x}$
419 \vspace{2em}
420 \end{DescribetensorstylesOption}
421
422 \DescribeOption{covariant-style}
423 \begin{DescribetensorstylesOption}{}
424 {greek, alph, arabic}{greek}
425 The alphabet to use when adding covariant indices automatically. Either Greek or Latin alphabets, or numbers.
426
427 For example: |\tensor[covariant-style=arabic]{2}{x}| gives
428 $\tensor[covariant-style=arabic]{2}{x}$
429 \vspace{2em}
430 \end{DescribetensorstylesOption}
431
432 \DescribeOption{specific-indices}
433 \begin{DescribetensorstylesOption}{}
434 {1,2,3,...}{}
435 When adding indices automatically, which ones should not be added as \texttt{default-indices}.
436 For instance, if default-indices is contra, which indices to add as covariant indices.
437
438 For example: |\tensor[specific-indices=2]{3}{x}| gives
439 $\tensor[specific-indices=2]{3}{x}$
440 \vspace{2em}
441 \end{DescribetensorstylesOption}
442
443 \DescribeOption{collapsed-indices}
444 \begin{DescribetensorstylesOption}{}
445 {true, false}{false}
446 Whether indices are spaced horizontally, \emph{i.e.} there will not be a covariant index under a contravariant index and vice versa, or not.
447
448 For example: |\tensor[specific-indices=2,collapsed-indices=true]{3}{x}| gives
449 $\tensor[specific-indices=2,collapsed-indices=true]{3}{x}$
450 \vspace{2em}
451 \end{DescribetensorstylesOption}
452
453 \DescribeOption{index-marker}
454 \begin{DescribetensorstylesOption}{}
455 {\textbackslash\textvisiblespace, ., ;, ...}{\textbackslash\textvisiblespace}
456 If indices are not collapsed, what symbol to use to fill in the blanks.
457
458 For example: |\tensor[specific-indices=2,index-marker=.]{3}{x}| gives
459 $\tensor[specific-indices=2,index-marker=.]{3}{x}$
460 \vspace{2em}
461 \end{DescribetensorstylesOption}
462
463
464 \subsection{Dirac options}
465 \DescribeOption{bra-ket}
466 \begin{DescribetensorstylesOption}{}
467 {true, false}{true}
468 Whether delimiters should be added to tensors.
469 \vspace{2em}
470 \end{DescribetensorstylesOption}
471
472 \DescribeOption{scale-var}
473 \begin{DescribetensorstylesOption}{}
474 {auto, none, big, bigg, Big, Bigg}{auto}
475 How the delimiters should scale with the tensor.
476 \vspace{2em}
477 \end{DescribetensorstylesOption}
478
479 \DescribeOption{delims-var}
480 \begin{DescribetensorstylesOption}{}
481 {\textbackslash rvert\textbackslash lbrace, \textbackslash rbrace\textbackslash lvert, ...}{ \textbackslash lbrace\textbackslash rvert}
482 Which delimiters to add. If scale-var is auto, the delimiters must be usable with \textbackslash left and \textbackslash right, else any symbol can be used.
483 \vspace{2em}
484 \end{DescribetensorstylesOption}
485
486 \DescribeOption{mix-delims}
487 \begin{DescribetensorstylesOption}{}
488 {true, false}{true}
489 If two tensors are following each other, and the delimiters between them are identical, whether to display one or two.
490
491 For example: |\tensor[preset=bra]{1}{x}\tensor[preset=ket]{1}{y}| gives
492 $\tensor[preset=bra]{1}{x}\tensor[preset=ket]{1}{y}$ while |\tensor[preset=bra, mix-delims=false]{1}{x}\tensor[preset=ket]{1}{y}| gives
493 $\tensor[preset=bra, mix-delims=false]{1}{x}\tensor[preset=ket]{1}{y}$
494 \vspace{2em}
495 \end{DescribetensorstylesOption}
496 % \begin{DescribetensorstylesOption}{format}
497 % {regular, x}{regular}
498 % A short description of the option.
499 % \end{DescribetensorstylesOption}
500
501
502 %% ------------------------------------
503 % \section{Tips \& Tricks}
504 % Here you can add some tips about your package.
505 \section{Using the package}
506 In this section, we will take the example of a user trying to write an article in which they will need several tensor notations.
507
508 Let's say that the user wants to represent tensors using an Einstein convention.
509 More specifically they want to represent purely covariant and purely contravariant tensors with this convention.
510
511 There are two ways to do that with \pkgName.
512 The first is to define two new commands to represent tensors, one for covariant tensors and one for contravariant tensors.
513 \begin{lstlisting}
514 \DeclareTensorsCmd{\covariantTensor}[preset=einstein]
515 \DeclareTensorsCmd{\contravariantTensor}[preset=einstein, default-indices=contra]
516 \end{lstlisting}
517 The second is to take advantage of the star variant of the commands and to define only one that does both.
518 \begin{lstlisting}
519 \DeclareTensorsCmd{\myTensor}[preset=einstein, preset*=einstein, default-indices*=contra]
520 \end{lstlisting}
521 We will take the second approach for this example.
522
523 \DeclareTensorsCmd{\myTensor}[preset=einstein, preset*=einstein, default-indices*=contra]
524
525 Now whenever they want to represent a tensor in their article, all they have to do is call this new command:
526 \begin{center}
527 \texttt{\textbackslash myTensor\{4\}\{e\}} $\rightarrow \myTensor{4}{e}$
528 \texttt{\textbackslash myTensor*\{4\}\{e\}} $\rightarrow \myTensor*{4}{e}$
529 \end{center}
530
531 Unfortunately, the user now needs to represent a tensor with both covariant and contravariant indices, something they did not anticipate.
532 Fortunately \pkgName offers two ways to do just that.
533 First, the user could use an option to specify which indices should be contravariant or covariant:
534 \begin{center}
535 \texttt{\textbackslash myTensor\{4\}\{e\}[specific-indices=\{1,4\}]} $\rightarrow \myTensor[specific-indices={1,4}]{4}{e}$
536 Which is equivalent to
537 \texttt{\textbackslash myTensor*\{4\}\{e\}[specific-indices*=\{2,3\}]} $\rightarrow \myTensor*[specific-indices*={2,3}]{4}{e}$
538 \end{center}
539 Or they can use an optional argument of the command to pass the indices directly.
540 \begin{center}
541 \texttt{\textbackslash myTensor\{4\}\{e\}[\^{}a\_bc\^{}d]} $\rightarrow \myTensor{4}{e}[^a_bc^d]$
542 Which is equivalent to
543 \texttt{\textbackslash myTensor*\{4\}\{e\}[\^{}a\_bc\^{}d]} $\rightarrow \myTensor*{4}{e}[^a_bc^d]$
544 \end{center}
545 This is more powerful since the user will have full control over the positions of the indices and their values.
546 This is especially useful to pass indices with sub- or superscripts or even an entire command as an index.
547 For example
548 \begin{center}
549 \texttt{\textbackslash myTensor\{4\}\{e\}[\^{}\{a\_i\}\_bc\^{}\{\textbackslash myTensor\{2\}\{a\}\}]} $\rightarrow \myTensor{4}{e}[^{a_i}_bc^{\myTensor{2}{a}}]$
550 \end{center}
551
552 Our user is now quite far into their document, but now they want to represent a tensor with another convention, let's say an engineer notation with recursive underlines.
553 Perhaps they want to present their document to students, and to show them that other notations exist.
554
555 They can do this in two ways. First they can define a new command
556 \begin{lstlisting}
557 \DeclareTensorsCmd{\tensorEngineer}[preset=engineer]
558 \end{lstlisting}
559
560 This works quite well and it preserves the separation of content and form.
561 But it adds a new command that will only be used once, and so it is not really optimal in terms of memory or computation.
562
563 Alternatively they can change the behavior of their already existing command locally:
564 \begin{center}
565 \texttt{\textbackslash myTensor\{4\}\{e\}[preset=engineer]} $\rightarrow \myTensor[preset=engineer]{4}{e}$
566 \end{center}
567 This avoids the declaration of a new command but it partially links content and form, so our user may have to be careful if they want to change the notation of their document.
568
569 For the last part of their document our user wants to use another convention entirely.
570 Moreover it is a complex one: they want to use delimiters, like a Dirac convention, and to change the font of the tensor depending on the rank.
571 Since they want this behavior for the rest of their document, redefining the display at each call is out of the question.
572 So they have two options:
573
574 They can define a new command for this convention, or, the approach we will follow, they can use the \texttt{\textbackslash tensorsset} command to override the options globally after its call.
575 \begin{lstlisting}
576 \myTensor{2}{a}
577
578 \tensorsset{\myTensor}[preset=math, bra-ket=true, delims-var = \lbrace\rvert]
579
580 \myTensor{4}{e} and \myTensor{2}{a}
581 \end{lstlisting}
582 Gives us:
583
584 $\myTensor{2}{a}$
585
586 % \tensorsset{\myTensor}[scale-var=auto]
587 \tensorsset{\myTensor}[preset=math, bra-ket=true, delims-var = {\lbrace\rvert}]
588
589 $\myTensor{4}{e}$ and $\myTensor{2}{a}$
590
591 Now, let us say that users want to switch the notation convention within the whole document.
592 Thanks to \pkgName this is trivial, all they need to do is go back to the function declaration and change the options at the beginning of the document they gave:
593 \begin{lstlisting}
594 \DeclareTensorsCmd{\myTensor}[preset=arrow, preset*=math]
595 \end{lstlisting}
596 Plus they also used an engineer preset once, which will not be changed either, but since this call was to explicitly show this notation there is no need for a change.
597 However, if many different presets have been used through the document, the previous approach remains tedious.
598 Therefore, another approach can be to redefine presets themselves.
599
600
601 \section{Sources of inspiration}
602 Many packages have been used as sources of inspiration to build \pkgName{}:
603 \begin{itemize}
604 \item \url{https://gitlab.com/RomainNOEL/latex3_template_pkg} for LateX3 template.
605 \item \href{https://ctan.org/pkg/mattens}{mattens} package from Danie Els for complex vector notations.
606 \item \href{https://ctan.org/pkg/hhtensor}{hhtensor} package from Harald Harders to print tensors with arrow, bold, or uline.
607 \item \href{https://ctan.org/pkg/tensor}{tensor} package from Philip G. Ratcliffe for Einstein tensor notation.
608 \item \href{https://ctan.org/pkg/tensind}{tensind} package from Javier Bezos for Einstein tensor notation.
609 \item \href{https://ctan.org/pkg/overarrows}{overarrows} package from Julien Labbé to draw arrows that stretch.
610 \item \href{https://ctan.org/pkg/braket}{braket} package from Donald Arseneau for Dirac bra-ket notation.
611 \item \href{https://ctan.org/pkg/physics}{physics} package from Sergio C. de la Barrera for vec, braket and too many things.
612 \end{itemize}
613
614
615 %% ------------------------------------
616 \section{Known issues}
617 Some limitations have been faced.
618 \begin{itemize}
619 \item when using |\dots| with |collapsed-indices|,
620 this is due to the tentative of context determination employed by |\dots| which interferes with the \pkgName.
621 A simple workaround is to use |\ldots| instead.
622 \item if you are mixing delimiters using two
623 variables of different sizes with automatic scale, \emph{e.g.}
624 |\tensor[preset=bra, mix-delims=true, scale-var=auto]{n}{\frac| |{1}{A}}\tensor*[preset*=ket, mix-delims*=true, scale-var*=auto]{n}{B}|, then the delimiters will not have the same size.
625 A simple solution is to set the desired scale for the \textquote{wrong} delimiter.
626 \end{itemize}
627
628
629 % \subsection{Other issues}
630 % \begin{itemize}
631 % \item |enumitem| is not working.
632 % \end{itemize}
633
634
635 % \subsection*{Todo}
636 % List of thing that could be improved (any volunteer welcome):
637 % \begin{itemize}
638 % \item add more options.
639 % \end{itemize}
640
641 \subsection{Contributors}
642 \begin{itemize}
643 \item Maelwen THOMAS
644 \item Laurent NAVARRO
645 \end{itemize}
646
647
648 \section{License}
649 \pkgName is licensed under the terms of the
650 % \href{https://creativecommons.org/licenses/by-sa/4.0/}{Creative Commons Attribution-ShareAlike 4.0}
651 \href{https://www.latex-project.org/lppl/lppl-1-3c/}{LaTeX project public license (LPPL) 1.3c}
652 license.
653
654
655 \end{document}
656 % EoF
657
658
659 % \begin{documentation}
660 % \begin{macro|function|variable}{\nameMacro}
661 % \begin{syntax}
662 % \cs{nameMacro}\oarg{option1=value1, ...}\marg{tempkg}
663 % \textrm{where the options are (default marked as} \defopt{default}\textrm{):}
664 % \meta{footer template} = \oarg{\defopt{tempkg} \textbar ... }
665 % \end{syntax}
666 % Description of |nameMacro| which xxx.
667 % \end{macro|function|variable}
668 % \end{documentation}
669 %%%%
670 % \begin{implementation}
671 % \begin{macro|function|variable}[added= 2025-02-12, updated= 2025-02-12]{\nameMacro}
672 % \begin{arguments}
673 % \item |width| Name of the option to add, this name should also correspond to the name of the environment followed by the suffix 'env'.
674 % \end{arguments}
675 % Description
676 % \changes{v1.0.1}{2025-02-12}{original version}
677 % \UnitTested % NOT FOR VARIABLES NOR FUNCTIONS
678 % \TestFiles{tempkg-test-xxx} % NOT FOR VARIABLES
679 % \begin{macrocode}
680 %% MY CODE
681 % \end{macrocode}
682 % \end{macro|function|variable}
683 % \end{implementation}
684
685
686
687 % \begin{implementation}
688 % \begin{macro}[added= 2025-02-12, updated= 2025-02-12]{\nameMacro}
689 % \begin{arguments}
690 % \item |width| Name of the option to add, this name should also correspond to the name of the environment followed by the suffix 'env'.
691 % \end{arguments}
692 % Description
693 % \changes{v1.0.1}{2025-02-12}{original version}
694 % \UnitTested
695 % \TestFiles{tempkg-test-048}
696 % \begin{macrocode}
697 %% MY CODE
698 % \end{macrocode}
699 % \end{macro}
700 % \end{implementation}