?? tt11
字號(hào):
.NHMacros with arguments.PPThe next step is to define macros that can change from oneuse to the nextaccording to parameters supplied as arguments.To make this work, we need two things:first, when we define the macro, we have to indicate that someparts of it will be provided as arguments when the macro is called.Then when the macro is calledwe have to provide actual argumentsto be plugged into the definition..PPLet us illustrate by defining a macro.BD .SMthat will print its argument two pointssmaller than the surrounding text.That is, the macro call.P1^SM TROFF.P2will produce.UC TROFF ..PPThe definition of.BD .SMis.P1^de SM\es\-2\e\e$1\es+2^^.P2Within a macro definition,the symbol.BD \e\e$nrefers to the.BD n thargumentthat the macro was called with.Thus.BD \e\e$1is the string to be placed in a smaller pointsize when.BD .SMis called..PPAs a slightly more complicated version, the following definition of.BD .SMpermits optional second and third argumentsthat will be printed in the normal size:.P1^de SM\e\e$3\es\-2\e\e$1\es+2\e\e$2^^.P2Arguments not provided when the macro is called are treatedas empty,so.P1^SM TROFF ),.P2produces.UC TROFF ),while.P1^SM TROFF ). (.P2produces.UC TROFF ). (It is convenient to reverse the order of arguments because trailing punctuationis much more common than leading..PPBy the way, the number of arguments that a macro was called withis available in number register.BD .$ ..PPThe following macro.BD ^BDis the one used to make the`bold roman' we have been using for.UL troffcommand names in text.It combines horizontal motions, width computations,and argument rearrangement..P1 2\&.de BD\e&\e\e$3\ef1\e\e$1\eh'\-\ew'\e\e$1'u+1u'\e\e$1\efP\e\e$2\&...P2The.BD \ehand.BD \ewcommands need no extra backslash, as we discussed above.The.BD \e&is there in case the argument begins with a period..WS.PPTwo backslashes are needed with the.BD \e\e$ncommands, though,to protect one of them when the macro isbeing defined.Perhaps a second example will make this clearer.Consider a macro called.BD .SHwhichproduces section headings rather like those in this paper,with the sections numbered automatically,and the title in bold in a smaller size.The use is.P1^SH "Section title ...".P2(If the argument to a macro is to contain blanks,then it must be.ulsurroundedby double quotes,unlike a string, where only one leading quote is permitted.).PPHere is the definition of the.BD .SHmacro:.P1.ta .75i 1.15i^nr SH 0 \e" initialize section number^de SH^sp 0.3i^ft B^nr SH \e\en(SH+1 \e" increment number^ps \e\en(PS\-1 \e" decrease PS\e\en(SH. \e\e$1 \e" number. title^ps \e\en(PS \e" restore PS^sp 0.3i^ft R^^.P2The section number is kept in number register SH, which is incremented eachtime just before it is used.(A number register may have the same name as a macrowithout conflict but a string may not.).PPWe used.BD \e\en(SHinstead of.BD \en(SHand.BD \e\en(PSinstead of.BD \en(PS .If we had used.BD \en(SH ,we would get the value of the register at the time the macro was.uldefined,not at the time it was.ulused.If that's what you want, fine,but not here.Similarly,by using.BD \e\en(PS ,we get the point size at the time the macro is called..WS.PPAs an example that does not involve numbers,recall our.BD .NPmacro which had a.P1^tl 'left'center'right'.P2We could make these into parameters by using instead.P1^tl '\e\e*(LT'\e\e*(CT'\e\e*(RT'.P2so the title comes from three strings called LT, CT and RT.If these are empty, then the title will be a blank line.Normally CT would be set with something like.P1\&^ds CT - % -.P2to give just the page number between hyphens (as on the top of this page),but a user could supply private definitions forany of the strings.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -