Köşeli ayraç içinde veya kırpmak için makro kullanamazsınız

Aug 17 2020

Bir kullanıcı komutuyla isteğe bağlı şekil parametrelerini varsayılan olarak tanımlamaya çalışıyorum ancak [ ]. Sonraki örnek, trim=0 0 0 0ile değiştirdiğimde bir istisna atıyor trim=\trim.

\usepackage[demo]{graphicx}

\newcommand{\trim}{0 0 0 0}

\begin{document}
    
    \begin{figure}[htbp]
        \centering
        \includegraphics[width=\linewidth,trim=0 0 0 0,clip]{Figure}
        \caption{blablabla.}
    \end{figure}
        
\end{document}

Ayrıca amacım, width=\linewidth,trim=0 0 0 0,clipiçindeki tüm cümleyi [ ]onunla değiştirebileceğim bir emir tanımlamaktır .

Yanıtlar

6 UlrichDiez Aug 17 2020 at 17:02

20 AĞUSTOS 2020'DE DÜZENLEME

Bir kez daha (Ulrich Diez) kendimi utanç verici bir duruma soktum:

Aşağıdakileri yazarken, ben (Ulrich Diez) köşeli parantezlerin [ve ]–küme parantezlerinin aksine– kategori kodu 1 ve 2 olmadıklarını, kategori kodu 12'nin sıradan karakterleri olduklarını ve bu nedenle köşeli parantezler olduğunu düşünmedim makro argümanlar içinde ortaya çıkabilir. Aşağıdaki koddan daha az karmaşık ve çok daha kısa:

\documentclass{article}

\usepackage[demo]{graphicx}

\newcommand\exchange[2]{#2#1}
\newcommand{\trim}{0 0 0 0}

\begin{document}
    
    \begin{figure}[htbp]
        \centering
        \expandafter\exchange\expandafter{\trim}{%
           \includegraphics[width=\linewidth,trim=%
        },clip]{/path/to/graphics/file.jpg}%%%%%
        % Why two captions?
        \caption{Testing of the Y-axis.}%%%%%
        \caption{blablabla.}%%%%%
    \end{figure}
        
\end{document}

Sekans

\expandafter\exchange\expandafter{\trim}{%
   \includegraphics[width=\linewidth,trim=%
},clip]{/path/to/graphics/file.jpg}%%%%%

aşağıdakileri tetikler:

\expandafterGenişletilmesine-zinciri potansiyel müşteriler \trim:

\exchange{0 0 0 0}{%
   \includegraphics[width=\linewidth,trim=%
},clip]{/path/to/graphics/file.jpg}%%%%%

Artan \exchangeverim:

\includegraphics[width=\linewidth,trim=%
0 0 0 0,clip]{/path/to/graphics/file.jpg}%%%%%

20 AĞUSTOS 2020 DÜZENLEME SONU



\trim-Komutunun tanımı şekilden şekle değişebiliyorsa, o zaman, örneğin, \romannumeral0-genişleme- ve argüman alışverişi-tekniğini kullanabilirsiniz - -genişlemenin özü \romannumeral0:

  • TeX , roma rakamlarıyla temsil edilecek "sayı " miktarına ait jetonları toplarken genişletilebilir jetonları genişletir .
  • TeX'in " sayı " miktarını toplarken bulduğu ilk belirteç bir rakamsa , örneğin, 0" sayıya" ait jetonları toplama işlemi, daha fazla basamak veya olmayan bir şey toplama sürecine dönüşür. bir rakamdır ve bu nedenle toplama sürecini sonlandırır. Genişletilebilir belirteçler, rakamları toplarken genişletilir. Bir rakam dizisini sonlandıran bir boşluk belirteci, daha fazla basamak toplama sürecini sonlandırır ve sessizce atılır.
  • Toplanan sayı pozitif değilse, TeX karşılığında herhangi bir jeton teslim etmeden " sayı " miktarını oluşturan jetonları sessizce yutacaktır .

Bu \romannumeral, sonunda pozitif olmayan bir sayının bulunması sağlandığı sürece TeX'i çok sayıda genişletme ve argüman değiş tokuşu yapması için kandırmak için kullanılabileceği anlamına gelir .

\documentclass{article}

\usepackage[demo]{graphicx}

\newcommand\exchange[2]{#2#1}
\newcommand{\trim}{0 0 0 0}

\begin{document}
    
    \begin{figure}[htbp]
        \centering
        \expandafter\includegraphics\expandafter[%
          \romannumeral0%
          \expandafter\exchange
          \expandafter{\trim}{ width=\linewidth,trim=},clip%
        ]{/path/to/graphics/file.jpg}%%%%%
        % Why two captions?
        \caption{Testing of the Y-axis.}%%%%%
        \caption{blablabla.}%%%%%
    \end{figure}
        
\end{document}

Sekans

\expandafter\includegraphics\expandafter[%
  \romannumeral0%
  \expandafter\exchange
  \expandafter{\trim}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%

aşağıdakileri tetikler:

(Üst düzey) genişletme elde etme \expandaftersüreci, bir sonraki ancak bir belirtecin üst düzey genişlemesini sağlama sürecini tetikler ve bir sonraki jetonun üst düzey genişlemesini elde etme süreci sona erdiğinde sona erer. . Böylece:

% Process of obtaining the top-level-expansion of the first \expandafter in
% progress, this process triggers the process of obtaining the top-level-
% expansion of the next but one token:
\includegraphics\expandafter[%
  \romannumeral0%
  \expandafter\exchange
  \expandafter{\trim}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%

Birinciden giden bir sonraki ancak bir jeton \expandafterda bir \expandafter, dolayısıyla:

% Process of obtaining the top-level-expansion of the first \expandafter in 
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter in
% progress, this process triggers the process of obtaining the top-level-
% expansion of the next but one token:
[%
  \romannumeral0%
  \expandafter\exchange
  \expandafter{\trim}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%

İkinciden iki sonraki jetonu giden \expandafterolan \romannumeral, böylece:

% Process of obtaining the top-level-expansion of the first \expandafter in 
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter in 
% progress, this process triggerd the process of obtaining the top-level-
% expansion of \romannumeral:
[%
  % Process of obtaining the top-level-expansion of \romannumeral in progress;
  %   Sub-process of \romannumeral-expansion for gathering tokens of a <number>-
  %   quantity in progress:
  0%
  \expandafter\exchange
  \expandafter{\trim}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%

TeX rakamı bulur 0, bu nedenle bir \romannumeral" sayı " miktarının jetonlarını toplama alt süreci, daha fazla rakam toplama sürecine veya rakam dizisini sonlandıran bir şeye dönüşür:

% Process of obtaining the top-level-expansion of the first \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of \romannumeral:
[%
  % Process of obtaining the top-level-expansion of \romannumeral in progress;
  %   Sub-process of \romannumeral-expansion for gathering more digits of a
  %   <number>-quantity in progress; digit "0" found so far:
  \expandafter\exchange
  \expandafter{\trim}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%

" Sayı " miktarına ait daha fazla jeton / rakam ararken , TeX üçüncüyle karşılaşır \expandafter:

% Process of obtaining the top-level-expansion of the first \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of \romannumeral:
[%
  % Process of obtaining the top-level-expansion of \romannumeral in progress;
  %   Sub-process of \romannumeral-expansion for gathering more digits of a
  %   <number>-quantity in progress; digit "0" found so far:
  %     Process of obtaining the top-level-expansion of the third \expandafter
  %     in progress, this process triggers the process of obtaining the top-
  %     level-expansion of the next but one token:
  \exchange
  \expandafter{\trim}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%

Üçüncüsünden giden bir sonraki ancak bir jeton \expandafterşu \expandafterşekilde:

% Process of obtaining the top-level-expansion of the first \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of \romannumeral:
[%
  % Process of obtaining the top-level-expansion of \romannumeral in progress;
  %   Sub-process of \romannumeral-expansion for gathering more digits of a
  %   <number>-quantity in progress; digit "0" found so far:
  %     Process of obtaining the top-level-expansion of the third \expandafter
  %     in progress, this process triggerd the process of obtaining the top-
  %     level-expansion of the fourth \expandafter:
  \exchange
  %   Process of obtaining the top-level-expansion of the fourth \expandafter
  %   in progress, this process triggers the process of obtaining the top-
  %   level-expansion of the next but one token:
  {\trim}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%

Dördüncü bir sonraki ama bir belirteç giden \expandafterIS \trim, dördüncü üst düzey genişleme elde böylece sürecin \expandafteren üst düzey-genişleme elde etme süreci sona eren, \trimsonlandırıldığında olup:

% Process of obtaining the top-level-expansion of the first \expandafter in 
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of \romannumeral:
[%
  % Process of obtaining the top-level-expansion of \romannumeral in progress;
  %   Sub-process of \romannumeral-expansion for gathering more digits of a 
  %   <number>-quantity in progress, digit "0" found so far:
  %     Process of obtaining the top-level-expansion of the third \expandafter
  %     in progress, this process triggerd the process of obtaining the top-
  %     level-expansion of the fourth \expandafter:
  \exchange
  %  Process of obtaining the top-level-expansion of the fourth \expandafter
  %  terminated.
  {0 0 0 0}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%

Dördüncünün \expandafteren üst düzey genişlemesini elde etme süreci \expandaftersona erdiğinden, üçüncü sonların üst düzey genişlemesini elde etme süreci de sona erer:

% Process of obtaining the top-level-expansion of the first \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of \romannumeral:
[%
  % Process of obtaining the top-level-expansion of \romannumeral in progress;
  %   Sub-process of \romannumeral-expansion for gathering more digits of a
   %  <number>-quantity in progress, digit "0" found so far:
  %     Process of obtaining the top-level-expansion of the third \expandafter
  %     terminated.
  \exchange
  {0 0 0 0}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%

Üçüncüsünün en üst düzey genişlemesini elde etme süreci \expandaftersona ererken, \romannumeralgenişleme devam eder ve bu da genişlemeyi sağlar \exchange:

% Process of obtaining the top-level-expansion of the first \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of \romannumeral:
[%
  % Process of obtaining the top-level-expansion of \romannumeral in progress;
  %   Sub-process of \romannumeral-expansion for gathering more digits of a
  %   <number>-quantity in progress; digit "0" found so far:
  <space-token>width=\linewidth,trim=0 0 0 0,clip%
]{/path/to/graphics/file.jpg}%%%%%

TeX, bir boşluk belirteci bulur. Bu boşluk, belirteci son bulur daha çok bir basamak toplama alt proses ⟨number⟩ -Miktar ve sessizce atılır alır.

% Process of obtaining the top-level-expansion of the first \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of \romannumeral:
[%
  % Process of obtaining the top-level-expansion of \romannumeral in progress;
  %   Sub-process of \romannumeral-expansion for gathering more digits of a
  %   <number>-quantity terminated; number "0" found.
  width=\linewidth,trim=0 0 0 0,clip%
]{/path/to/graphics/file.jpg}%%%%%

Tex olarak Bulunan ⟨number⟩ , değeri -Miktar 0ise, 0pozitif bir değer, en üst düzey-genişleme elde etme işlemi değil \romannumeralsessizce şekillendirme belirteçleri yutarak sonlanıncaya ⟨number⟩ bir belirteç in teslim TeX olmadan -Miktar dönüş.

% Process of obtaining the top-level-expansion of the first \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of \romannumeral:
[%
  % Process of obtaining the top-level-expansion of \romannumeral terminated.
  width=\linewidth,trim=0 0 0 0,clip%
]{/path/to/graphics/file.jpg}%%%%%

Üst düzey genişlemeyi \romannumeralelde etme süreci \expandaftersona erdiğinden, ikinci sonun üst düzey genişlemesini elde etme süreci de sona erer:

% Process of obtaining the top-level-expansion of the first \expandafter in
% progress, this process triggerd the process of obtaining the top-level-
% expansion of the second \expandafter:
\includegraphics
% Process of obtaining the top-level-expansion of the second \expandafter
% terminated.
[%
  width=\linewidth,trim=0 0 0 0,clip%
]{/path/to/graphics/file.jpg}%%%%%

İkincinin en üst düzey genişlemesini \expandafterelde etme süreci \expandaftersona ererken, ilkinin üst düzey genişlemesini elde etme süreci de sona erer:

% Process of obtaining the top-level-expansion of the first \expandafter
% terminated.
\includegraphics
[%
  width=\linewidth,trim=0 0 0 0,clip%
]{/path/to/graphics/file.jpg}%%%%%