summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/bodeplot/bodeplot.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/pgf/contrib/bodeplot/bodeplot.dtx')
-rw-r--r--graphics/pgf/contrib/bodeplot/bodeplot.dtx321
1 files changed, 220 insertions, 101 deletions
diff --git a/graphics/pgf/contrib/bodeplot/bodeplot.dtx b/graphics/pgf/contrib/bodeplot/bodeplot.dtx
index 17c1b53119..c7fcd076e6 100644
--- a/graphics/pgf/contrib/bodeplot/bodeplot.dtx
+++ b/graphics/pgf/contrib/bodeplot/bodeplot.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment
%
-% Copyright (C) 2021 by Rushikesh Kamalapurkar <rlkamalapurkar@gmail.com>
+% Copyright (C) 2021-2024 by Rushikesh Kamalapurkar <rlkamalapurkar@gmail.com>
% -----------------------------------------------------------
%
% This file may be distributed and/or modified under the conditions of
@@ -20,7 +20,7 @@
%<package>\ProvidesPackage{bodeplot}
%<package>\RequirePackage{pdftexcmds}
%<package>\RequirePackage{ifplatform}
-%<package>\RequirePackage{environ}
+%<package>\RequirePackage{xparse}
%<package>\RequirePackage{pgfplots}
%<package> \pgfplotsset{compat=1.18}
%<package> \usepgfplotslibrary{groupplots}
@@ -30,6 +30,7 @@
\usepackage{cprotect}
\usepackage[declutter]{bodeplot}
\usepackage[colorlinks]{hyperref}
+\usepackage{fancyvrb }
\usepackage{iftex}
\iftutex % LuaTeX, XeTeX
\usepackage{fontspec}
@@ -68,7 +69,7 @@
%</driver>
% \fi
%
-% \CheckSum{1645}
+% \CheckSum{1758}
%
% \changes{v1.0}{2021/10/25}{Initial release}
% \changes{v1.0.4}{2021/11/05}{Fixed unintended optional argument macro expansion}
@@ -78,11 +79,12 @@
% \changes{v1.0.8}{2022/07/06}{Added a new class option `declutter'}
% \changes{v1.1.0}{2022/07/06}{Fixed phase wrapping in gnuplot mode}
% \changes{v1.1.1}{2022/07/31}{Enable Hz and rad units}
+% \changes{v1.1.5}{2024/01/11}{Detect `babel-french' to handle active characters}
%
% \GetFileInfo{bodeplot.sty}
% \DoNotIndex{\newcommand,\xdef,\gdef,\def,\edef,\addplot,\approx,\arabic,\opt,\typ,\obj,\else,\if@pgfarg,\if@Hzarg,\if@radarg,\if@declutterarg,\fi,\begin,\end,\feature,\footnotesize,\draw,\detokenize,\DeclareOption,\foreach,\ifdim,\ifodd,\Im,\Re,\let,\newif,\nextgroupplot,\noexpand,\expandafter,\unexpanded,\PackageError,\PackageWarning,\relax,\RequirePackage,\tikzset,\pgfmathsetmacro,\pgfmathtruncatemacro,\ProcessOptions}
%
-% \title{The \textsf{bodeplot} package\\version 1.1.4}
+% \title{The \textsf{bodeplot} package\\version 1.1.5}
% \author{Rushikesh Kamalapurkar \\ \texttt{rlkamalapurkar@gmail.com}}
%
% \maketitle
@@ -103,6 +105,7 @@
% Since version 1.0.8, the |bodeplot| package places all |gnuplot| temporary files in the working directory. The package option |declutter| restores the original behavior where the temporary files are placed in a folder called |gnuplot|.
% \subsection{Limitations}
% \begin{itemize}
+% \item If French language support is needed through the |babel| package, \textbf{the |babel| package has to be loaded before the |bodeplot| package}. The options |french| or |main=french| need to be passed to |babel| locally, and not via class options.
% \item In |pgf| mode, Bode phase plots and Nichols charts in TF form wrap angles so that they are always between -180 and 180$^\circ$ or $-\pi$ and $-\pi$ radian. As such, these plots will show phase wrapping discontinuities. Since v1.1.1, in |gnuplot| mode, the package uses the |smooth unwrap| filter to correct wrapping discontinuities. As of now, I have not found a way to do this in |pgf| mode, any merge requests or ideas you may have are welcome! Since v1.1.4, you can redefine the |n@mod| macro using the commands |\makeatletter\renewcommand{\n@mod}{\n@mod@p}\makeatother| to wrap the phase between 0 and 360$^\circ$ or $0$ and $2\pi$ radian. The commands |\makeatletter\renewcommand{\n@mod}{\n@mod@n}\makeatother| will wrap the phase between -360 and 0$^\circ$ or $-2\pi$ and $0$ radian.
% \item Use of the |declutter| option with other directory management tools such as a |tikzexternalize| prefix is not recommended.
% \end{itemize}
@@ -456,28 +459,33 @@ Nyquist plots with additional commands, using two different macros
% \end{itemize}
% The options |{opt}| can be any |key=value| options that are supported by the |pgfplots| macros they are added to.
-% For example, given a transfer function \begin{equation}G(s) = 10\frac{s(s+0.1+0.5\mathrm{i})(s+0.1-0.5\mathrm{i})}{(s+0.5+10\mathrm{i})(s+0.5-10\mathrm{i})},\label{eq:ZPKExample}\end{equation} its Bode plot over the frequency range $[0.01,100]$ can be generated using\\
-% |\BodeZPK [blue,thick]|\\
-% | {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}|\\
-% | {0.01}{100}|\\
-% which generates the plot in Figure \ref{simpleBode}. If a delay is not specified, it is assumed to be zero. If a gain is not specified, it is assumed to be 1. By default, each of the axes, excluding ticks and labels, are 5cm wide and 2.5cm high. The width and the height, along with other properties of the plots, the axes, and the group can be customized using native |pgf| keys as shown in the example below.
+% For example, given a transfer function \begin{equation}G(s) = 10\frac{s(s+0.1+0.5\mathrm{i})(s+0.1-0.5\mathrm{i})}{(s+0.5+10\mathrm{i})(s+0.5-10\mathrm{i})},\label{eq:ZPKExample}\end{equation} its Bode plot over the frequency range $[0.01,100]$ can be generated using
+%\begin{verbatim}
+%\BodeZPK [blue,thick]
+% {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}
+% {0.01}{100}
+%\end{verbatim}
+% which generates the plot in Figure \ref{simpleBode}. In this example, a delay is not specified, so it is assumed to be zero. A gain is not specified, so it is assumed to be 1. A single comma-separated list of options |[blue,thick]| is passed, so it is passed on to the |\addplot| commands in both the magnitude and the phase plots. The default plots are thick black lines and each of the axes, excluding ticks and labels, are 5cm wide and 2.5cm high.
%
% \begin{figure}
% \begin{center}
% \BodeZPK[blue,thick]{z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}{0.01}{100}
-% \cprotect\caption{\label{simpleBode}Output of the default |\BodeZPK| macro.}
+% \cprotect\caption{\label{simpleBode}Output of the |\BodeZPK| macro.}
% \end{center}
% \end{figure}
-% As demonstrated in this example, if a single comma-separated list of options is passed, it applies to both the magnitude and the phase plots. Without any optional arguments, we gets a thick black Bode plot.
-%
-% A linear approximation of the Bode plot with customization of the plots, the axes, and the group can be generated using\\
-% |\BodeZPK[plot/mag/{red,thick},plot/ph/{blue,thick},|\\
-% | axes/mag/{ytick distance=40,xmajorticks=true,|\\
-% | xlabel={Frequency (rad/s)}},axes/ph/{ytick distance=90},|\\
-% | group/{group style={group size=2 by 1,horizontal sep=2cm,|\\
-% | width=4cm,height=2cm}},approx/linear]|\\
-% | {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}|\\
-% | {0.01}{100}|\\
+%
+% The width and the height, along with other properties of the plots, the axes, and the group can be customized using native |pgf| keys. For example, a linear approximation of the Bode plot with customization of the plots, the axes, and the group can be generated using
+%\begin{verbatim}
+%\BodeZPK[%
+% plot/mag/{red,thick},
+% plot/ph/{blue,thick},
+% axes/mag/{ytick distance=40,xmajorticks=true,xlabel={Frequency (rad/s)}},
+% axes/ph/{ytick distance=90},
+% group/{group style={group size=2 by 1,horizontal sep=2cm,width=4cm,height=2cm}},
+% approx/linear]
+% {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}
+% {0.01}{100}
+%\end{verbatim}
% which generates the plot in Figure \ref{customBode}.
%
% \begin{figure}
@@ -494,11 +502,14 @@ Nyquist plots with additional commands, using two different macros
%
% \noindent Plots the Bode plot of a transfer function given in TF format. The three mandatory arguments include: (1) a list of tuples comprised of the coefficients in the numerator and the denominator of the transfer function and the transport delay, (2) the lower end of the frequency range for the $x-$ axis, and (3) the higher end of the frequency range for the $x-$axis. The coefficients are entered as a comma-separated list, in order from the highest degree of $s$ to the lowest, with zeros for missing degrees. The optional arguments are the same as |\BodeZPK|, except that linear/asymptotic approximation is not supported, so |approx/...| is ignored.
%
-% For example, given the same transfer function as (\ref{eq:ZPKExample}) in TF form and with a small transport delay, \begin{equation}G(s) = e^{-0.01s}\frac{s(10s^2+2s+2.6)}{(s^2+s+100.25)},\label{eq:TFExample}\end{equation} its Bode plot over the frequency range $[0.01,100]$ can be generated using\\
-% |\BodeTF[commands/mag/{\node at (axis cs: 2.1,0) |\\
-% | [circle,fill,inner sep=0.05cm,label=below:{$\omega_{gc}$}]{};}]|\\
-% | {num/{10,2,2.6,0},den/{1,1,100.25},d/0.01}|\\
-% | {0.01}{100}|\\
+% For example, given the same transfer function as (\ref{eq:ZPKExample}) in TF form and with a small transport delay, \begin{equation}G(s) = e^{-0.01s}\frac{s(10s^2+2s+2.6)}{(s^2+s+100.25)},\label{eq:TFExample}\end{equation} its Bode plot over the frequency range $[0.01,100]$ can be generated using
+%\begin{verbatim}
+%\BodeTF[%
+% commands/mag/{\node at (axis cs: 2.1,0) [circle,fill,inner sep=0.05cm,
+% label=below:{$\omega_{gc}$}]{};}]
+% {num/{10,2,2.6,0},den/{1,1,100.25},d/0.01}
+% {0.01}{100}
+%\end{verbatim}
% which generates the plot in Figure \ref{simpleBodeTF}. Note the $0$ added to the numerator coefficients to account for the fact that the numerator does not have a constant term in it. Note the semicolon after the TikZ command passed to the |\commands| option.
%
% \begin{figure}
@@ -608,14 +619,14 @@ Nyquist plots with additional commands, using two different macros
% All 20 of the macros defined by combinations of |Type|, |Feature|, and |Approx|, and any |gnuplot| (or |pgfplot| if the |pgf| class option is loaded) compatible function of the 20 macros can be used as |plot-command| in the |addBodeComponentPlot| macro. This is sufficient to generate the Bode plot of any rational transfer function with delay. For example, the Bode phase plot in Figure \ref{multiBodeZPK} can also be generated using:
%\begin{verbatim}
%\begin{BodePhPlot}[ytick distance=90]{0.01}{100}
-% \addBodeComponentPlot[black,thick]{\PhZero{0}{0} + \PhZero{-0.1}{-0.5} +
-% \PhZero{-0.1}{0.5} + \PhPole{-0.5}{-10} + \PhPole{-0.5}{10} +
-% \PhK{10}{0}}
-% \addBodeComponentPlot[red,dashed,thick] {\PhZeroLin{0}{0} +
-% \PhZeroLin{-0.1}{-0.5} + \PhZeroLin{-0.1}{0.5} +
+% \addBodeComponentPlot[black,thick]{%
+% \PhZero{0}{0} + \PhZero{-0.1}{-0.5} + \PhZero{-0.1}{0.5} +
+% \PhPole{-0.5}{-10} + \PhPole{-0.5}{10} + \PhK{10}{0}}
+% \addBodeComponentPlot[red,dashed,thick] {%
+% \PhZeroLin{0}{0} + \PhZeroLin{-0.1}{-0.5} + \PhZeroLin{-0.1}{0.5} +
% \PhPoleLin{-0.5}{-10} + \PhPoleLin{-0.5}{10} + \PhKLin{10}{20}}
-% \addBodeComponentPlot[blue,dotted,thick] {\PhZeroAsymp{0}{0} +
-% \PhZeroAsymp{-0.1}{-0.5} + \PhZeroAsymp{-0.1}{0.5} +
+% \addBodeComponentPlot[blue,dotted,thick] {%
+% \PhZeroAsymp{0}{0} + \PhZeroAsymp{-0.1}{-0.5} + \PhZeroAsymp{-0.1}{0.5} +
% \PhPoleAsymp{-0.5}{-10} + \PhPoleAsymp{-0.5}{10} + \PhKAsymp{10}{40}}
%\end{BodePhPlot}
%\end{verbatim}
@@ -683,16 +694,20 @@ Nyquist plots with additional commands, using two different macros
% \hspace*{2em}\marg{z/\marg{zeros},p/\marg{poles},k/\marg{gain},d/\marg{delay}}\\
% \hspace*{2em}\marg{min-freq}\marg{max-freq}
%
-% \noindent Plots the Nyquist plot of a transfer function given in ZPK format with a thick red $+$ marking the critical point (-1,0). The mandatory arguments are the same as |\BodeZPK|. Since there is only one plot in a Nyquist diagram, the |\typ| specifier in the optional argument tuples is not needed. As such, the supported optional argument tuples are |plot/{opt}|, which passes |{opt}| to |\addplot|, |axes/{opt}|, which passes |{\opt}| to the |axis| environment, and |tikz/{opt}|, which passes |{\opt}| to the |tikzpicture| environment. Asymptotic/linear approximations are not supported in Nyquist plots. If just |{opt}| is provided as the optional argument, it is interpreted as |plot/{opt}|. Arrows to indicate the direction of increasing $\omega$ can be added by adding |\usetikzlibrary{decorations.markings}| and |\usetikzlibrary{arrows.meta}| to the preamble and then passing a tuple of the form\\
-%|plot/{postaction=decorate,decoration={markings,|\\
-%| mark=between positions 0.1 and 0.9 step 5em with|\\
-%| {\arrow{Stealth| |[length=2mm, blue]}}}}|\\
+% \noindent Plots the Nyquist plot of a transfer function given in ZPK format with a thick red $+$ marking the critical point (-1,0). The mandatory arguments are the same as |\BodeZPK|. Since there is only one plot in a Nyquist diagram, the |\typ| specifier in the optional argument tuples is not needed. As such, the supported optional argument tuples are |plot/{opt}|, which passes |{opt}| to |\addplot|, |axes/{opt}|, which passes |{\opt}| to the |axis| environment, and |tikz/{opt}|, which passes |{\opt}| to the |tikzpicture| environment. Asymptotic/linear approximations are not supported in Nyquist plots. If just |{opt}| is provided as the optional argument, it is interpreted as |plot/{opt}|. Arrows to indicate the direction of increasing $\omega$ can be added by adding |\usetikzlibrary{decorations.markings}| and |\usetikzlibrary{arrows.meta}| to the preamble and then passing a tuple of the form
+%\begin{verbatim}
+%plot/{postaction=decorate,decoration={markings,
+% mark=between positions 0.1 and 0.9 step 5em with {%
+% \arrow{Stealth| |[length=2mm, blue]}}}}
+%\end{verbatim}
%\textbf{Caution:} with a high number of samples, adding arrows in this way may cause the error message |! Dimension too big|.
%
-% For example, the command\\
-% |\NyquistZPK[plot/{red,thick,samples=2000},axes/{blue,thick}]|\\
-% | {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}|\\
-% | {-30}{30}|\\
+% For example, the command
+%\begin{verbatim}
+%\NyquistZPK[plot/{red,thick,samples=2000},axes/{blue,thick}]
+% {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}
+% {-30}{30}
+%\end{verbatim}
% generates the Nyquist plot in Figure \ref{simpleNyquistZPK}.
%
% \begin{figure}
@@ -707,13 +722,15 @@ Nyquist plots with additional commands, using two different macros
% \hspace*{2em}\marg{num/\marg{coeffs},den/\marg{coeffs},d/\marg{delay}}\\
% \hspace*{2em}\marg{min-freq}\marg{max-freq}
%
-% \noindent Nyquist plot of a transfer function given in TF format. Same mandatory arguments as |\BodeTF| and same optional arguments as |\NyquistZPK|. For example, the command\\
-% |\NyquistTF[plot/{green,thick,samples=500,postaction=decorate,|\\
-% | decoration={markings,|\\
-% | mark=between positions 0.1 and 0.9 step 5em|\\
-% | with{\arrow{Stealth[length=2mm, blue]}}}}]|\\
-% | {num/{10,2,2.6,0},den/{1,1,100.25}}|\\
-% | {-30}{30}|\\
+% \noindent Nyquist plot of a transfer function given in TF format. Same mandatory arguments as |\BodeTF| and same optional arguments as |\NyquistZPK|. For example, the command
+%\begin{verbatim}
+%\NyquistTF[plot/{green,thick,samples=500,postaction=decorate,
+% decoration={markings,
+% mark=between positions 0.1 and 0.9 step 5em
+% with{\arrow{Stealth[length=2mm, blue]}}}}]
+% {num/{10,2,2.6,0},den/{1,1,100.25}}
+% {-30}{30}
+%\end{verbatim}
% generates the Nyquist plot in Figure \ref{simpleNyquistTF}.
%
% \begin{figure}
@@ -765,10 +782,12 @@ Nyquist plots with additional commands, using two different macros
% \hspace*{2em}\marg{num/\marg{coeffs},den/\marg{coeffs},d/\marg{delay}}\\
% \hspace*{2em}\marg{min-freq}\marg{max-freq}
%
-% \noindent Nichols chart of a transfer function given in TF format. Same arguments as |\NyquistTF|. For example, the command\\
-% |\NicholsTF[plot/{green,thick,samples=2000}]|\\
-% | {num/{10,2,2.6,0},den/{1,1,100.25},d/0.01}|\\
-% | {0.001}{100}|\\
+% \noindent Nichols chart of a transfer function given in TF format. Same arguments as |\NyquistTF|. For example, the command
+%\begin{verbatim}
+%\NicholsTF[plot/{green,thick,samples=2000}]
+% {num/{10,2,2.6,0},den/{1,1,100.25},d/0.01}
+% {0.001}{100}
+%\end{verbatim}
% generates the Nichols chart in Figure \ref{simpleNicholsTF}.
%
% \begin{figure}
@@ -821,7 +840,8 @@ Nyquist plots with additional commands, using two different macros
% \changes{v1.0.3}{2021/11/03}{Added jobname to gnuplot prefix}
% \changes{v1.0.8}{2022/07/06}{Fixed issue \#6}
% \changes{v1.1.4}{2023/10/12}{Changed phase wrapping in pgf mode}
-% This code is needed to support both |pgfplots| and |gnuplot| simultaneously. New macros are defined for the |pow| and |mod| functions to address differences between the two math engines. We start by processing the class options.
+% \changes{v1.1.5}{2024/01/11}{Added babel option to handle active characters}
+% We start by processing the class options.
% \begin{macrocode}
\newif\if@pgfarg\@pgfargfalse
\DeclareOption{pgf}{
@@ -841,7 +861,7 @@ Nyquist plots with additional commands, using two different macros
}
\ProcessOptions\relax
% \end{macrocode}
-% Then, we define new macros to unify |pgfplots| and |gnuplot|.
+% Then, we define new macros to unify |pgfplots| and |gnuplot|. New macros are defined for the |pow| and |mod| functions to address differences between the two math engines.
% \begin{macrocode}
\newcommand{\n@mod}[2]{(#1)-((round((#1)/(#2)))*(#2))}
\newcommand{\n@mod@p}[2]{(#1)-((floor((#1)/(#2)))*(#2))}
@@ -885,6 +905,14 @@ Nyquist plots with additional commands, using two different macros
% \end{macro}
% \end{macro}
% \end{macro}
+% \begin{macro}{\if@babel@french}
+% Check if the |babel| package is loaded with French language option.
+% \begin{macrocode}
+\newif\if@babel@french\@babel@frenchfalse
+\@ifpackagewith{babel}{french}{\@babel@frenchtrue}{}
+\@ifpackagewith{babel}{main=french}{\@babel@frenchtrue}{}
+% \end{macrocode}
+% \end{macro}
% \begin{macro}{bode@style}
% Default axis properties for all plot macros are collected in this |pgf| style.
% \begin{macrocode}
@@ -1295,6 +1323,20 @@ Nyquist plots with additional commands, using two different macros
\end{tikzpicture}
}
% \end{macrocode}
+% The following code handles active characters to avoid conflicts with `babel.'\changes{v1.1.5}{2023/01/11}{Added code to handle active characters}
+% \begin{macrocode}
+\if@babel@french
+ \let\Orig@BodeZPK\BodeZPK
+ \renewcommand{\BodeZPK}{%
+ \shorthandoff{;:!?}%
+ \BodeZPK@Shorthandoff
+ }
+ \newcommand{\BodeZPK@Shorthandoff}[4][]{%
+ \Orig@BodeZPK[#1]{#2}{#3}{#4}%
+ \shorthandon{;:!?}%
+ }
+\fi
+% \end{macrocode}
% \end{macro}
% \begin{macro}{\BodeTF}
% Implementation of this macro is very similar to the |\BodeZPK| macro above. The only difference is the lack of linear and asymptotic plots and slightly different parsing of the mandatory arguments. \changes{v1.0.3}{2021/11/03}{Added Tikz option} \changes{v1.1.0}{2022/07/06}{Fixed phase wrapping in gnuplot mode}\changes{v1.1.1}{2022/07/31}{Enabled `Hz' and `rad' units for frequency and phase, respectively}\changes{v1.1.4}{2023/10/12}{Changed phase wrapping in pgf mode}
@@ -1355,7 +1397,21 @@ Nyquist plots with additional commands, using two different macros
\end{groupplot}
\end{tikzpicture}
}
-% \end{macrocode}
+% \end{macrocode}
+% The following code handles active characters to avoid conflicts with `babel.'\changes{v1.1.5}{2023/01/11}{Added code to handle active characters}
+% \begin{macrocode}
+\if@babel@french
+ \let\Orig@BodeTF\BodeTF
+ \renewcommand{\BodeTF}{%
+ \shorthandoff{;:!?}%
+ \BodeTF@Shorthandoff
+ }
+ \newcommand{\BodeTF@Shorthandoff}[4][]{%
+ \Orig@BodeTF[#1]{#2}{#3}{#4}%
+ \shorthandon{;:!?}%
+ }
+\fi
+% \end{macrocode}
% \end{macro}
% \begin{macro}{\addBodeZPKPlots}
% This macro is designed to issues multiple |\addplot| macros for the same set of poles, zeros, gain, and delay. All of the work is done by the |\build@ZPK@plot| macro. \changes{v1.0.1}{2021/10/29}{Improved optional argument handling.}\changes{v1.1.1}{2022/07/31}{Enabled `Hz' and `rad' units for frequency and phase, respectively}\changes{v1.1.3}{2022/11/02}{Changed implementation to respect user-supplied domain}
@@ -1462,12 +1518,16 @@ Nyquist plots with additional commands, using two different macros
% \end{macrocode}
%\end{macro}
% \begin{environment}{BodePhPlot}
-% An environment to host phase plot macros that pass parametric functions to |\addplot| macros. Uses the defaults specified in |bode@style| to create a shortcut that includes the |tikzpicture| and |semilogaxis| environments.\changes{v1.1.0}{2022/07/20}{Added separate environments for phase and magnitude plots}\changes{v1.1.1}{2022/07/31}{Enabled `Hz' and `rad' units for frequency and phase, respectively}\changes{v1.1.2}{2022/10/29}{Defined using the `NewEnviron' command from the `environ' package to fix conflicts with externalization}
+% An environment to host phase plot macros that pass parametric functions to |\addplot| macros. Uses the defaults specified in |bode@style| to create a shortcut that includes the |tikzpicture| and |semilogaxis| environments.\changes{v1.1.0}{2022/07/20}{Added separate environments for phase and magnitude plots}\changes{v1.1.1}{2022/07/31}{Enabled `Hz' and `rad' units for frequency and phase, respectively}\changes{v1.1.2}{2022/10/29}{Defined using the `NewEnviron' command from the `environ' package to fix conflicts with externalization}\changes{v1.1.5}{2023/01/11}{Defined using the `NewDocumentEnvironment' command from the `xparse' package and added a hook to handle active characters}
% \begin{macrocode}
-\NewEnviron{BodePhPlot}[3][]{
+\if@babel@french
+ \AddToHook{env/BodePhPlot/begin}{\shorthandoff{;:!?}}
+\fi
+\NewDocumentEnvironment{BodePhPlot}{O{}mm+b}{
\parse@env@opt{#1}
- \edef\temp@cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt@tikz}]
- \noexpand\begin{semilogxaxis}[
+ \edef\temp@cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt@tikz}]}
+ \temp@cmd
+ \edef\temp@cmd{\noexpand\begin{semilogxaxis}[
ph@y@label,
freq@label,
bode@style,
@@ -1476,22 +1536,25 @@ Nyquist plots with additional commands, using two different macros
domain=#2:#3,
height=2.5cm,
\unexpanded\expandafter{\opt@axes}
- ]
- }
- \temp@cmd
- \BODY
+ ]}
+ \temp@cmd
+ #4
\end{semilogxaxis}
\end{tikzpicture}
-}
+}{}
% \end{macrocode}
% \end{environment}
% \begin{environment}{BodeMagPlot}
-% An environment to host magnitude plot macros that pass parametric functions to |\addplot| macros. Uses the defaults specified in |bode@style| to create a shortcut that includes the |tikzpicture| and |semilogaxis| environments.\changes{v1.1.0}{2022/07/20}{Added separate environments for phase and magnitude plots}\changes{v1.1.1}{2022/07/31}{Enabled `Hz' and `rad' units for frequency and phase, respectively}\changes{v1.1.2}{2022/10/29}{Defined using the `NewEnviron' command from the `environ' package to fix conflicts with externalization}
+% An environment to host magnitude plot macros that pass parametric functions to |\addplot| macros. Uses the defaults specified in |bode@style| to create a shortcut that includes the |tikzpicture| and |semilogaxis| environments.\changes{v1.1.0}{2022/07/20}{Added separate environments for phase and magnitude plots}\changes{v1.1.1}{2022/07/31}{Enabled `Hz' and `rad' units for frequency and phase, respectively}\changes{v1.1.2}{2022/10/29}{Defined using the `NewEnviron' command from the `environ' package to fix conflicts with externalization}\changes{v1.1.5}{2023/01/11}{Defined using the `NewDocumentEnvironment' command from the `xparse' package and added a hook to handle active characters}
% \begin{macrocode}
-\NewEnviron{BodeMagPlot}[3][]{
+\if@babel@french
+ \AddToHook{env/BodeMagPlot/begin}{\shorthandoff{;:!?}}
+\fi
+\NewDocumentEnvironment{BodeMagPlot}{O{}mm+b}{
\parse@env@opt{#1}
- \edef\temp@cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt@tikz}]
- \noexpand\begin{semilogxaxis}[
+ \edef\temp@cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt@tikz}]}
+ \temp@cmd
+ \edef\temp@cmd{\noexpand\begin{semilogxaxis}[
bode@style,
freq@label,
xmin={#2},
@@ -1500,22 +1563,25 @@ Nyquist plots with additional commands, using two different macros
height=2.5cm,
ylabel={Gain (dB)},
\unexpanded\expandafter{\opt@axes}
- ]
- }
- \temp@cmd
- \BODY
+ ]}
+ \temp@cmd
+ #4
\end{semilogxaxis}
\end{tikzpicture}
-}
+}{}
% \end{macrocode}
% \end{environment}
% \begin{environment}{BodePlot}
-% Same as |BodeMagPlot|. The |BodePlot| environment is deprecated as of v1.1.0, please use the |BodePhPlot| and |BodeMagPlot| environments instead.\changes{v1.0.3}{2021/11/03}{Added tikz option to environments}\changes{v1.1.0}{2022/02/20}{Deprecated BodePlot environment}\changes{v1.1.1}{2022/07/31}{Enabled `Hz' and `rad' units for frequency and phase, respectively}\changes{v1.1.2}{2022/10/29}{Defined using the `NewEnviron' command from the `environ' package to fix conflicts with externalization}
+% Same as |BodeMagPlot|. The |BodePlot| environment is deprecated as of v1.1.0, please use the |BodePhPlot| and |BodeMagPlot| environments instead.\changes{v1.0.3}{2021/11/03}{Added tikz option to environments}\changes{v1.1.0}{2022/02/20}{Deprecated BodePlot environment}\changes{v1.1.1}{2022/07/31}{Enabled `Hz' and `rad' units for frequency and phase, respectively}\changes{v1.1.2}{2022/10/29}{Defined using the `NewEnviron' command from the `environ' package to fix conflicts with externalization}\changes{v1.1.5}{2023/01/11}{Defined using the `NewDocumentEnvironment' command from the `xparse' package and added a hook to handle active characters}
% \begin{macrocode}
-\NewEnviron{BodePlot}[3][]{
+\if@babel@french
+ \AddToHook{env/BodePlot/begin}{\shorthandoff{;:!?}}
+\fi
+\NewDocumentEnvironment{BodePlot}{O{}mm+b}{
\parse@env@opt{#1}
- \edef\temp@cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt@tikz}]
- \noexpand\begin{semilogxaxis}[
+ \edef\temp@cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt@tikz}]}
+ \temp@cmd
+ \edef\temp@cmd{\noexpand\begin{semilogxaxis}[
bode@style,
freq@label,
xmin={#2},
@@ -1523,13 +1589,12 @@ Nyquist plots with additional commands, using two different macros
domain=#2:#3,
height=2.5cm,
\unexpanded\expandafter{\opt@axes}
- ]
- }
- \temp@cmd
- \BODY
+ ]}
+ \temp@cmd
+ #4
\end{semilogxaxis}
\end{tikzpicture}
-}
+}{}
% \end{macrocode}
% \end{environment}
% \subsubsection{Internal macros}
@@ -1812,6 +1877,20 @@ Nyquist plots with additional commands, using two different macros
\end{tikzpicture}
}
% \end{macrocode}
+% The following code handles active characters to avoid conflicts with `babel.'\changes{v1.1.5}{2023/01/11}{Added code to handle active characters}
+% \begin{macrocode}
+\if@babel@french
+ \let\Orig@NyquistZPK\NyquistZPK
+ \renewcommand{\NyquistZPK}{%
+ \shorthandoff{;:!?}%
+ \NyquistZPK@Shorthandoff
+ }
+ \newcommand{\NyquistZPK@Shorthandoff}[4][]{%
+ \Orig@NyquistZPK[#1]{#2}{#3}{#4}%
+ \shorthandon{;:!?}%
+ }
+\fi
+% \end{macrocode}
% \end{macro}
% \begin{macro}{\NyquistTF}
% Implementation of this macro is very similar to the |\NyquistZPK| macro above. The only difference is a slightly different parsing of the mandatory arguments via |\build@TF@plot|. \changes{v1.0.3}{2021/11/03}{Added commands and tikz options}\changes{v1.1.1}{2022/07/31}{Enabled `Hz' and `rad' units for frequency and phase, respectively}
@@ -1851,6 +1930,20 @@ Nyquist plots with additional commands, using two different macros
\end{tikzpicture}
}
% \end{macrocode}
+% The following code handles active characters to avoid conflicts with `babel.'\changes{v1.1.5}{2023/01/11}{Added code to handle active characters}
+% \begin{macrocode}
+\if@babel@french
+ \let\Orig@NyquistTF\NyquistTF
+ \renewcommand{\NyquistTF}{%
+ \shorthandoff{;:!?}%
+ \NyquistTF@Shorthandoff
+ }
+ \newcommand{\NyquistTF@Shorthandoff}[4][]{%
+ \Orig@NyquistTF[#1]{#2}{#3}{#4}%
+ \shorthandon{;:!?}%
+ }
+\fi
+% \end{macrocode}
% \end{macro}
% \begin{macro}{\addNyquistZPKPlot}
% Adds Nyquist plot of a transfer function in ZPK form. This macro is designed to pass two parametric function to an |\addplot| macro. The parametric functions for phase (|\func@ph|) and magnitude (|\func@mag|) are built using the |\build@ZPK@plot| macro, converted to real and imaginary parts and passed to |\addplot| commands.\changes{v1.1.1}{2022/07/31}{Enabled `Hz' and `rad' units for frequency and phase, respectively}\changes{v1.1.3}{2022/11/02}{Changed implementation to respect user-supplied domain}
@@ -1897,26 +1990,29 @@ Nyquist plots with additional commands, using two different macros
% \end{macrocode}
%\end{macro}
%\begin{macro}{NyquistPlot}
-% An environment to host |\addNyquist...| macros that pass parametric functions to |\addplot|. Uses the defaults specified in |bode@style| to create a shortcut that includes the |tikzpicture| and |axis| environments. \changes{v1.0.3}{2021/11/03}{Added tikz option to environments}\changes{v1.1.2}{2022/10/29}{Defined using the `NewEniron' command from the `environ' package to fix conflicts with externalization}
+% An environment to host |\addNyquist...| macros that pass parametric functions to |\addplot|. Uses the defaults specified in |bode@style| to create a shortcut that includes the |tikzpicture| and |axis| environments. \changes{v1.0.3}{2021/11/03}{Added tikz option to environments}\changes{v1.1.2}{2022/10/29}{Defined using the `NewEniron' command from the `environ' package to fix conflicts with externalization}\changes{v1.1.5}{2023/01/11}{Defined using the `NewDocumentEnvironment' command from the `xparse' package and added a hook to handle active characters}
% \begin{macrocode}
-\NewEnviron{NyquistPlot}[3][]{
+\if@babel@french
+ \AddToHook{env/NyquistPlot/begin}{\shorthandoff{;:!?}}
+\fi
+\NewDocumentEnvironment{NyquistPlot}{O{}mm+b}{
\parse@env@opt{#1}
- \edef\temp@cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt@tikz}]
- \noexpand\begin{axis}[
+ \edef\temp@cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt@tikz}]}
+ \temp@cmd
+ \edef\temp@cmd{\noexpand\begin{axis}[
bode@style,
height=5cm,
domain=#2:#3,
xlabel={$\Re$},
ylabel={$\Im$},
\unexpanded\expandafter{\opt@axes}
- ]
- }
- \temp@cmd
+ ]}
+ \temp@cmd
\addplot [only marks,mark=+,thick,red] (-1 , 0);
- \BODY
+ #4
\end{axis}
\end{tikzpicture}
-}
+}{}
% \end{macrocode}
%\end{macro}
% \subsubsection{Internal commands\label{sec:NInternal}}
@@ -1953,11 +2049,11 @@ Nyquist plots with additional commands, using two different macros
% \end{macro}
% \subsection{Nichols charts}
% \begin{macro}{\NicholsZPK}
-% \changes{v1.0.3}{2021/11/03}{Added commands and tikz options}
+% \changes{v1.0.3}{2021/11/03}{Added commands and tikz options}\changes{v1.1.5}{2023/01/11}{Added code to handle active characters}
% \begin{macro}{\NicholsTF}
-% \changes{v1.0.3}{2021/11/03}{Added commands and tikz options}
+% \changes{v1.0.3}{2021/11/03}{Added commands and tikz options}\changes{v1.1.5}{2023/01/11}{Added code to handle active characters}
% \begin{macro}{NicholsChart}
-% \changes{v1.0.3}{2021/11/03}{Added tikz option to environments}\changes{v1.1.2}{2022/10/29}{Defined using the `NewEniron' command from the `environ' package to fix conflicts with externalization}
+% \changes{v1.0.3}{2021/11/03}{Added tikz option to environments}\changes{v1.1.2}{2022/10/29}{Defined using the `NewEniron' command from the `environ' package to fix conflicts with externalization}\changes{v1.1.5}{2023/01/11}{Defined using the `NewDocumentEnvironment' command from the `xparse' package and added a hook to handle active characters}
% \begin{macro}{\addNicholsZPKChart}
% \changes{v1.1.3}{2022/11/02}{Changed implementation to respect user-supplied domain}
% \begin{macro}{\addNicholsTFChart}
@@ -2002,6 +2098,17 @@ Nyquist plots with additional commands, using two different macros
\end{axis}
\end{tikzpicture}
}
+\if@babel@french
+ \let\Orig@NicholsZPK\NicholsZPK
+ \renewcommand{\NicholsZPK}{%
+ \shorthandoff{;:!?}%
+ \NicholsZPK@Shorthandoff
+ }
+ \newcommand{\NicholsZPK@Shorthandoff}[4][]{%
+ \Orig@NicholsZPK[#1]{#2}{#3}{#4}%
+ \shorthandon{;:!?}%
+ }
+\fi
\newcommand{\NicholsTF}[4][]{
\parse@N@opt{#1}
\gdef\func@mag{}
@@ -2043,23 +2150,35 @@ Nyquist plots with additional commands, using two different macros
\end{axis}
\end{tikzpicture}
}
-\NewEnviron{NicholsChart}[3][]{
+\if@babel@french
+ \let\Orig@NicholsTF\NicholsTF
+ \renewcommand{\NicholsTF}{%
+ \shorthandoff{;:!?}%
+ \NicholsTF@Shorthandoff
+ }
+ \newcommand{\NicholsTF@Shorthandoff}[4][]{%
+ \Orig@NicholsTF[#1]{#2}{#3}{#4}%
+ \shorthandon{;:!?}%
+ }
+ \AddToHook{env/NicholsChart/begin}{\shorthandoff{;:!?}}
+\fi
+\NewDocumentEnvironment{NicholsChart}{O{}mm+b}{
\parse@env@opt{#1}
- \edef\temp@cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt@tikz}]
- \noexpand\begin{axis}[
+ \edef\temp@cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt@tikz}]}
+ \temp@cmd
+ \edef\temp@cmd{\noexpand\begin{axis}[
ph@x@label,
bode@style,
domain=#2:#3,
height=5cm,
ylabel={Gain (dB)},
\unexpanded\expandafter{\opt@axes}
- ]
- }
- \temp@cmd
- \BODY
+ ]}
+ \temp@cmd
+ #4
\end{axis}
\end{tikzpicture}
-}
+}{}
\newcommand{\addNicholsZPKChart}[2][]{
\gdef\func@mag{}
\gdef\func@ph{}