Re: [問題] \def展開時機

看板LaTeX作者 (kezza)時間7年前 (2016/11/23 13:49), 編輯推噓4(406)
留言10則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《sppmg (sppmg)》之銘言: : 試了很久,實在不理解\def的展開時機。 : \def\cmd{define} 之後,若將\cmd傳入其他指令, : 是會在使用到當下展開(進行運算)其定義, 是的 : 還是說只有定義當下的值呢?(這好像不太合理) : 我想要讓目錄中,一般章節的條目顯示為:「一、 目錄名」 : 但附錄要維持「A、 附錄名」 : 所以我在.cls中首先改寫\thecontentslabel 設定 : \gdef\thecontentslabel@chapter{ : \ifx\@chapapp\appendixname % 判斷 \appendix : \appendixname\thecontentslabel、 : \else : \zhnumber{\thecontentslabel}、 : \fi} 恕刪 問題是 \ifx\@chapapp\appendixname 永遠都是 false,因為你忘了 \expandafter, 所以 TeX 直接拿字串 \@chapapp\appendixname 去給\ifx比了,然後因為第一二個字 \ 和 @ 不一樣所以變成 false 改成 \expandafter\ifx\@chapapp\appendixname 便可以了 或者簡單點用 apptools 的 \ifappendix (TeX) 或 \IfAppendix (LaTeX) 而你好像只要 chapter numbering 從\arabic 變成 \zhnumber 已而,應該不用寫一個 cls 這麼麻煩吧?直接 \renewcommand\thechapter{\zhnumber{chapter}} 不行嗎? -- 『我思故我在』怎樣從法文變成拉丁文的: je pense, donc je suis --- René Descartes, Discours de la Méthode (1637) ego sum, ego existo --- ____, Meditationes de Prima Philosophia (1641) ego cogito, ergo sum --- ____, Principia Philosophiae (1644) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.101.8 ※ 文章網址: https://www.ptt.cc/bbs/LaTeX/M.1479880159.A.13F.html

11/23 15:46, , 1F
高手.....
11/23 15:46, 1F

11/23 19:31, , 2F
啊!原來如此,非常感謝!(你有stack 帳號嗎?要不要去註解
11/23 19:31, 2F

11/23 19:33, , 3F
下?) 我會改\appendix 是因為zhnumber不接受英文(\@Alph)
11/23 19:33, 3F

11/23 19:36, , 4F
不直接改\thechapter是因為有些指令會用到他,譬如\thesect
11/23 19:36, 4F

11/23 19:37, , 5F
ion 定義:\thechapter.\@arabic\c@section 會變成 一.1
11/23 19:37, 5F

11/23 19:45, , 6F
def 展開方面,我還是有些疑問。晚點我再加上去,謝謝你囉!
11/23 19:45, 6F

11/23 19:46, , 7F
喔!對了,寫cls不是專為改數字啦!XD 是cls中有這項功能。
11/23 19:46, 7F

11/23 20:04, , 8F
將\expandafter加進 \gdef\thecontentslabel@chapter 後
11/23 20:04, 8F

11/23 20:07, , 9F
遇到附錄還是沒辦法改輸出耶!還是zhnumber,所以通通變"零"
11/23 20:07, 9F

11/23 20:25, , 10F
(而且在TL2012的zhnumber 還會直接error... 當初debug好久)
11/23 20:25, 10F
文章代碼(AID): #1ODItV4_ (LaTeX)
討論串 (同標題文章)
文章代碼(AID): #1ODItV4_ (LaTeX)