TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the MWE below.

\documentclass{memoir}
%---------------------------------------------------------------%
    \usepackage[english,slovene]{babel}
%---------------------------------------------------------------%
    \usepackage{lmodern}
    \usepackage{ragged2e}
    \usepackage[labelsep=space,
                labelfont={sf,bf},
                textfont=sf,
                justification=RaggedRight,
                caption=false]{subfig}
%---------------------------------------------------------------%
    \usepackage{tikz}
\usetikzlibrary{angles,
                quotes,
% added for compatibility with babel ...
                babel
                }
\usepackage[active,floats,tightpage]{preview}
    \setlength\PreviewBorder{1em}
\tikzset{
MA/.style args = {#1/#2}{% My Angle label position!
    draw, <->,
    angle radius=#1,
    angle eccentricity=#2},
every pic quotes/.append style = {inner sep=1pt, anchor=west},
        }
%---------------------------------------------------------------%
        \begin{document}
    \begin{figure}[h]\centering
    \subfloat[\label{fig:1.39a}]%
{
\begin{tikzpicture}
%---
\draw[->]   (-1mm,0) -- (44mm,0) coordinate (B);
\draw[->]   (0,-1mm) -- (0,33mm);
%---
\draw[thick,->]
    (0,0)       coordinate (O) --
    (60:33mm)   coordinate (A);
\pic [MA=11mm/1.1,"$\omega_c t+\varphi$",red] {angle = B--O--A};
%----------------
\end{tikzpicture}
}
   \subfloat[\label{fig:1.39br}]%
{
%%%%    ht-138b (bandpass signal)
\begin{tikzpicture}
%---
\draw[->]   (-1mm,0) -- (44mm,0) coordinate (B);
\draw[->]   (0,-1mm) -- (0,33mm);
%---
\draw[thick,->]
    (0,0)       coordinate (O) --
    (60:33mm)   coordinate (A);
\pic [MA=12mm/1.15,"$\varphi$",red] {angle = B--O--A};
%----------------
\end{tikzpicture}
}
\caption{}
    \end{figure}
\end{document}

As it is, it gives the well known error

! Argument of \language@active@arg> has an extra }. 

Under some circumstances, when I don't use \subfloat[...]{...}, it seems that the TikZ library babel is able to manage the problem of quotes; however, in presence of \subfloat this is not a case any more.

How to convince those packages to work together?

Addendum: meanwhile I got two answers. For my current works is more interesting ansfer of @egreg. Both his suggestion works for above MWE, however, real document is more complicated and suggested patch fails.

A MWE, which is more close to my real documents, is below:

\documentclass{memoir}
    \usepackage{lmodern}
    \usepackage{ragged2e}

    \usepackage[english,slovene]{babel}
    \usepackage[labelsep=space, labelfont={sf,bf},
                textfont=sf,
                format=hang,
                justification=RaggedRight,
                caption=false]{subfig}

    \usepackage{tikz}
\usetikzlibrary{angles,arrows,arrows.meta,
                quotes,
                babel% for compatibility with babel ...
                    }

 \tikzset{SDVpsp/.style = {%
%%-------------------------------------------------------------%%
LA/.style args = {##1/##2}{%
        line width=##1,
        draw=##2,%color
        arrows={-Straight Barb[]}
                        },
%%-------------------------------------------------------------%%
LC/.style args = {##1/##2}{%
        line width=##1,
        draw=##2%color
        },
%%-------------------------------------------------------------%%
MA/.style args = {##1/##2}{% My Angle label position
    draw, <->,
    angle radius=##1,
    angle eccentricity=##2},
%%-------------------------------------------------------------%%
every pic quotes/.append style = {%
    inner sep=2pt, anchor=west},
%%-------------------------------------------------------------%%
                          }% end of styles
         }% end of tikzset
\newcommand\ce{\mathsf{ce}}         

    \usepackage{etoolbox}
\makeatletter% <--- sugested by egreg
\patchcmd{\sf@@@subfloat}{#4}{\scantokens{#4\empty}}{}{}
\makeatother
%---------------------------------------------------------------%
    \usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}      
%---------------------------------------------------------------%
\begin{document}
    \begin{figure}[h]
%    \shorthandoff{"}% <--- suggested by egreg
\begin{sidecaption}{}%Fourier transform of $x_{1,pe}(f)$ and $x_{2,pe}(f)$}[fig:1.39]
\centering
    \subfloat[Phasor representation of $A\exp^{j2\pi f_c t+\varphi}$ \label{fig:1.39a}]
{
%%%%    ht-138a (bandpass signal)
\begin{tikzpicture}[SDVpsp,
    LA/.default = 0.3pt/gray,
                    ]
%---
\draw[LA]   (-1mm,0) -- (44mm,0) coordinate (B)
                                 node[below left] {$\Re$};
\draw[LA]   (0,-1mm) -- (0,44mm) node[below left] {$\Im$};
%---
\draw[LA=1pt/red]
    (0,0)       coordinate (O) --
    (60:33mm)   coordinate (A);
\pic [MA=11mm/1,"$\omega_c t+\varphi$",red] {angle = B--O--A};
%----------------
        \end{tikzpicture}
}
\hfill
    \subfloat[Complex envelope as a (slowly) varying amplitude and phase \label{fig:1.39b}]
{
%%%%    ht-138b (bandpass signal)
\begin{tikzpicture}[SDVpsp,
    LA/.default = 0.3pt/gray,
MA/.style args = {#1/#2}{% My Angle label position!
    draw, <->,
    angle radius=#1,
    angle eccentricity=#2},
every pic quotes/.append style = {inner sep=1pt, anchor=west},
                    ]
%---
\draw[LA]   (-1mm,0) -- (44mm,0) coordinate (B)
                                 node[below left] {$x_c$};
\draw[LA]   (0,-1mm) -- (0,44mm) node[below left] {$x_s$};
%---
\draw[LC=0.5pt/gray,densely dashed]
    (75:38mm) .. controls + (0.0,-0.3) and + (-0.3,0.3) ..
    (60:33mm) .. controls + (0.3,-0.3) and + (0.0,+0.3) ..
    (45:30mm) node[above right] {$x_\ce(t)$};
%---
\draw[LA=1pt/red]
    (0,0)       coordinate (O) -- node[above,sloped] {$A(t)$}
    (60:33mm)   coordinate (A);
\pic [MA=12mm/1.15,"$\varphi$",red] {angle = B--O--A};
%----------------
        \end{tikzpicture}
}
\end{sidecaption}
    \end{figure}
\end{document}

I observe:

  • patch with only one # gives error !Parameters must be numbered consecutively. This error I manage to cure with use of two #, i.e. with \patchcmd{\sf@@@subfloat}{##4}{\scantokens{##4\empty}}{}{}

  • unfortunately this patch doesn't help

  • use of \shorthandoff{"} solve the problem with quotes, however it had to be add to each figure (if I understand correctly egreg answer) ... so I'm very interested, if it is possible to developed a patch, which will works as desired.

share|improve this question
    
I think that \AtBeginEnvironment{figure}{\shorthandoff{"}} should work (requires etoolbox). – egreg Mar 2 at 7:16
up vote 5 down vote accepted

The problem is that the babel TikZ library solves the problem of the " shorthand by changing its category code when tikzpicture begins. However, when the tikzpicture is in the argument to \subfloat, this category code cannot be changed.

Solutions: use subcaption or patch \subfloat to do \scantokens:

\documentclass{memoir}
%---------------------------------------------------------------%
\usepackage[english,slovene]{babel}
%---------------------------------------------------------------%
\usepackage{lmodern}
\usepackage{ragged2e}
\usepackage[
  labelsep=space,
  labelfont={sf,bf},
  textfont=sf,
  justification=RaggedRight,
  caption=false
]{subfig}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\sf@@@subfloat}{#4}{\scantokens{#4\empty}}{}{}
\makeatother
%---------------------------------------------------------------%
\usepackage{tikz}
\usetikzlibrary{
  angles,
  quotes,
  babel
}


\tikzset{
  MA/.style args = {#1/#2}{% My Angle label position!
    draw, <->,
    angle radius=#1,
    angle eccentricity=#2},
  every pic quotes/.append style = {inner sep=1pt, anchor=west},
}
%---------------------------------------------------------------%

\begin{document}

\begin{figure}[h]\centering
\subfloat[\label{fig:1.39a}]{%
  \begin{tikzpicture}
  %---
  \draw[->]   (-1mm,0) -- (44mm,0) coordinate (B);
  \draw[->]   (0,-1mm) -- (0,33mm);
  %---
  \draw[thick,->]
    (0,0)       coordinate (O) --
    (60:33mm)   coordinate (A);
  \pic [MA=11mm/1.1,"$\omega_c t+\varphi$",red] {angle = B--O--A};
  %----------------
  \end{tikzpicture}
}\quad
\subfloat[\label{fig:1.39br}]{%
  %%%%    ht-138b (bandpass signal)
  \begin{tikzpicture}
  %---
  \draw[->]   (-1mm,0) -- (44mm,0) coordinate (B);
  \draw[->]   (0,-1mm) -- (0,33mm);
  %---
  \draw[thick,->]
    (0,0)       coordinate (O) --
    (60:33mm)   coordinate (A);
  \pic [MA=12mm/1.15,"$\varphi$",red] {angle = B--O--A};
  %----------------
  \end{tikzpicture}
}
\caption{Xyz}

\end{figure}

\end{document}

enter image description here

share|improve this answer
    
Your solution work fine in MWE, however in real document I receive error: Parameters must be numbered consequently <to be read again> ##. I need more time to figured-out the circumstances of this error. – Zarko Mar 1 at 9:48
1  
@Zarko I can only think to a # character inside a tikzpicture. An alternative, if you don't need the shorthand in captions, is to say \shorthandoff{"} after \begin{figure}. – egreg Mar 1 at 9:59
1  
Yes, this seems to be a case. For real pictures I use \tikzset{...}, where I have defined parameters, which value is determined in picture (as color of nodes, lines, and similar). Even use \shorthandoff{"} doesn't help. before error !Too many }'s is mentioned librarybabel.code.tex. Compilation stop with error Output loop--- 100 consecutive dead cycles – Zarko Mar 1 at 10:16
    
@Zarko Sorry, but without an example it's difficult to say. – egreg Mar 1 at 10:23
    
I managed to add in my question a MWE, which is more close to my real documents and exhibits mentioned troubles. – Zarko Mar 2 at 3:21

You should use the newer package subcaption package instead of subfig, and replace \subfloat{...} with the subfigure environment:

\documentclass{memoir}
%---------------------------------------------------------------%
\usepackage[english,slovene]{babel}
%---------------------------------------------------------------%
\usepackage{lmodern}
\usepackage{ragged2e}
\usepackage[labelsep=space,
            labelfont={sf,bf},
            textfont=sf,
            justification=RaggedRight]{subcaption}
%---------------------------------------------------------------%
\usepackage{tikz}
\usetikzlibrary{
  angles,
  quotes,
% added for compatibility with babel ...
  babel
}
\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}
\tikzset{
  MA/.style args = {#1/#2}{% My Angle label position!
    draw, <->,
    angle radius=#1,
    angle eccentricity=#2},
  every pic quotes/.append style = {inner sep=1pt, anchor=west},
}
%---------------------------------------------------------------%
\begin{document}

\begin{figure}[h]\centering
  \begin{subfigure}{0.49\textwidth}
    \centering
    \begin{tikzpicture}
      % ---
      \draw[->]   (-1mm,0) -- (44mm,0) coordinate (B);
      \draw[->]   (0,-1mm) -- (0,33mm);
      % ---
      \draw[thick,->]
      (0,0)       coordinate (O) --
      (60:33mm)   coordinate (A);
      \pic [MA=11mm/1.1,"$\omega_c t+\varphi$",red] {angle = B--O--A};
      % ----------------
    \end{tikzpicture}
    \caption{}
    \label{fig:1.39a}
  \end{subfigure}
  \hfill
  \begin{subfigure}{0.49\textwidth}
    \centering
    %%%% ht-138b (bandpass signal)
    \begin{tikzpicture}
      % ---
      \draw[->]   (-1mm,0) -- (44mm,0) coordinate (B);
      \draw[->]   (0,-1mm) -- (0,33mm);
      % ---
      \draw[thick,->]
      (0,0)       coordinate (O) --
      (60:33mm)   coordinate (A);
      \pic [MA=12mm/1.15,"$\varphi$",red] {angle = B--O--A};
      % ----------------
    \end{tikzpicture}
    \caption{}
    \label{fig:1.39br}
  \end{subfigure}
  \caption{}
\end{figure}

\end{document}

Output

share|improve this answer
1  
Thank you for your answer. Changing of package I can consider in new LaTeX project, in existing ones require to much work (few hundreds images ...). – Zarko Mar 1 at 9:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.