ไม่สามารถใช้มาโครภายในวงเล็บหรือสำหรับการตัดแต่ง
ฉันกำลังพยายามกำหนดรูปพารามิเตอร์ทางเลือกเป็นค่าเริ่มต้นด้วยคำสั่งผู้ใช้ แต่ฉันไม่สามารถใช้ภายในไฟล์[ ]
. ตัวอย่างถัดไปแสดงข้อยกเว้นเมื่อฉันแทนที่trim=0 0 0 0
ด้วย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}
นอกจากนี้วัตถุประสงค์ของฉันคือกำหนดคำสั่งเช่นฉันสามารถแทนที่ทั้งประโยคที่width=\linewidth,trim=0 0 0 0,clip
อยู่ข้างใน[ ]
ได้
คำตอบ
แก้ไขในวันที่ 20 สิงหาคม 2020
อีกครั้งที่ฉัน (Ulrich Diez) ทำให้ตัวเองตกอยู่ในสถานการณ์ที่น่าอับอาย:
ในขณะที่เขียนสิ่งต่างๆด้านล่างฉัน (Ulrich Diez) ไม่ได้คิดถึงความจริงที่ว่าวงเล็บเหลี่ยม[
และ]
- ไม่เหมือนกับวงเล็บปีกกา - ไม่ใช่ของรหัสหมวดหมู่ 1 และ 2 แต่เป็นอักขระธรรมดาของรหัสหมวดหมู่ 12 ดังนั้นจึงเป็นวงเล็บเหลี่ยม สามารถเกิดขึ้นภายในอาร์กิวเมนต์แมโคร ซับซ้อนน้อยกว่าและสั้นกว่าโค้ดด้านล่างมากคือ:
\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}
ลำดับ
\expandafter\exchange\expandafter{\trim}{%
\includegraphics[width=\linewidth,trim=%
},clip]{/path/to/graphics/file.jpg}%%%%%
เรียกสิ่งต่อไปนี้:
\expandafter
นำไปสู่การที่จะขยาย -chain \trim
:
\exchange{0 0 0 0}{%
\includegraphics[width=\linewidth,trim=%
},clip]{/path/to/graphics/file.jpg}%%%%%
การขยาย\exchange
ผลตอบแทน:
\includegraphics[width=\linewidth,trim=%
0 0 0 0,clip]{/path/to/graphics/file.jpg}%%%%%
สิ้นสุดการแก้ไขในวันที่ 20 สิงหาคม 2563
หากคำจำกัดความของ\trim
-command สามารถเปลี่ยนจากรูปเป็นรูปได้คุณสามารถเช่นใช้\romannumeral0
เทคนิค -expansion- และอาร์กิวเมนต์ - แลกเปลี่ยน - ส่วนสำคัญของ\romannumeral0
-expansion คือ:
- TeX ขยายโทเค็นที่ขยายได้ในขณะที่รวบรวมโทเค็นที่เป็นของ⟨number⟩ -ปริมาณที่จะแสดงเป็นตัวเลขโรมัน
- หากโทเค็นแรกที่ TeX พบในขณะที่รวบรวม⟩number⟩ -quantity เป็นตัวเลขเช่น
0
กระบวนการรวบรวมโทเค็นที่เป็นของ⟨number⟩ -quantity จะกลายเป็นกระบวนการรวบรวมตัวเลขที่มากขึ้นหรือสิ่งที่ไม่ใช่ ตัวเลขจึงยุติกระบวนการรวบรวม โทเค็นที่ขยายได้จะขยายในขณะที่รวบรวมตัวเลข โทเค็นเว้นวรรคที่ยุติลำดับตัวเลขจะยุติกระบวนการรวบรวมตัวเลขจำนวนมากขึ้นและถูกทิ้งโดยไม่โต้ตอบ - หากจำนวนที่รวบรวมไม่เป็นบวก TeX จะกลืนโทเค็นที่สร้างจำนวน⟨number⟩ -quantity โดยไม่ส่งโทเค็นใด ๆ ตอบแทน
นี่เป็นนัยว่า\romannumeral
สามารถใช้เพื่อหลอกให้ TeX ทำการขยายและแลกเปลี่ยนการโต้แย้งได้มากตราบเท่าที่มั่นใจได้ว่าในท้ายที่สุดจะพบจำนวนที่ไม่เป็นบวก
\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}
ลำดับ
\expandafter\includegraphics\expandafter[%
\romannumeral0%
\expandafter\exchange
\expandafter{\trim}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%
เรียกสิ่งต่อไปนี้:
ขั้นตอนการได้รับส่วนขยาย (ระดับบนสุด -) ของ\expandafter
ทริกเกอร์กระบวนการส่งมอบการขยายระดับบนสุดของรายการถัดไป แต่หนึ่งโทเค็นและยุติเมื่อกระบวนการได้รับส่วนขยายระดับบนสุดของรายการถัดไป แต่โทเค็นหนึ่งสิ้นสุดลง . ดังนั้น:
% 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}%%%%%
โทเค็นถัดไป แต่เป็นโทเค็นที่ส่งออกจากอันแรก\expandafter
ก็คือ\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 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}%%%%%
โทเค็นถัดไป แต่เป็นโทเค็นที่ส่งออกจากที่สอง\expandafter
คือ\romannumeral
:
% 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 พบตัวเลข0
ดังนั้น\romannumeral
กระบวนการย่อยของการรวบรวมโทเค็นของจำนวน ⟨number⟩จะกลายเป็นกระบวนการรวบรวมตัวเลขมากขึ้นหรือสิ่งที่ยุติลำดับตัวเลข:
% 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}%%%%%
ในขณะที่ค้นหาโทเค็น / หลักเพิ่มเติมที่เป็นของ⟨number⟩ -quantity TeX พบรายการที่สาม\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}%%%%%
โทเค็นถัดไป แต่เป็นโทเค็นหนึ่งที่ส่งออกจากที่สาม\expandafter
คือ\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 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}%%%%%
ถัดไป แต่อย่างหนึ่งที่ส่งออกจากโทเค็นที่สี่\expandafter
มี\trim
ดังนั้นกระบวนการของการได้รับระดับบนสุดขยายตัวของคนที่สี่\expandafter
สิ้นสุดเมื่อกระบวนการของการได้รับยอดระดับการขยายตัวของ\trim
เป็นสิ้นสุด:
% 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}%%%%%
เมื่อกระบวนการได้รับส่วนขยายระดับบนสุดของหน่วยที่สี่\expandafter
สิ้นสุดลงกระบวนการของการได้รับส่วนขยายระดับบนสุดของส่วนขยายที่สาม\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
% terminated.
\exchange
{0 0 0 0}{ width=\linewidth,trim=},clip%
]{/path/to/graphics/file.jpg}%%%%%
เมื่อกระบวนการได้รับส่วนขยายระดับบนสุดของส่วนที่สาม\expandafter
สิ้นสุดลง- การขยายจะ\romannumeral
ดำเนินต่อไปซึ่งจะทำให้เกิดการขยายตัว\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 ค้นหา Space-token Space-token นั้นยุติกระบวนการย่อยในการรวบรวมตัวเลขจำนวนมากขึ้นของจำนวนnumber⟩ -quantity และถูกละทิ้งไปอย่างเงียบ ๆ
% 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}%%%%%
ในฐานะที่เป็นเท็กซ์พบ⟨number⟩ -quantity ที่มีค่า0
ในขณะที่0
ไม่ได้เป็นค่าบวกกระบวนการของการได้รับยอดระดับการขยายตัวของ\romannumeral
การสิ้นสุดเงียบกลืนสัญญาณการขึ้นรูปที่⟨number⟩ -quantity โดยไม่ต้องส่งมอบในเท็กซ์โทเค็นใด ๆ กลับ.
% 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}%%%%%
เมื่อกระบวนการได้รับส่วนขยายระดับบนสุด\romannumeral
สิ้นสุดลงกระบวนการรับส่วนขยายระดับบนสุดของครั้งที่สอง\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
% terminated.
[%
width=\linewidth,trim=0 0 0 0,clip%
]{/path/to/graphics/file.jpg}%%%%%
เมื่อกระบวนการได้รับส่วนขยายระดับบนสุดของวินาที\expandafter
สิ้นสุดลงกระบวนการรับส่วนขยายระดับบนสุดของไฟเฟิร์สก็\expandafter
สิ้นสุดลงเช่นกัน:
% 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}%%%%%