2010-03-10 14 views
9

मैं \part* कमांड को फिर से परिभाषित करना चाहता हूं ताकि यह स्वचालित रूप से एक सामग्री पंक्ति जोड़ सके। यह मुश्किल साबित होता है क्योंकि मैं अपने तारांकित संस्करण के अंदर मूल \part* कमांड का पुन: उपयोग करना चाहता हूं।लाटेक्स: तारांकित आदेश को फिर से परिभाषित करना

आम तौर पर (अर्थात अतारांकित आदेश के लिए) मैं इसे इस तरह करना होगा:

\let\[email protected]\part 
\renewcommand\part[2][]{ 
    \[email protected][#1]{#2} 
    … rest of definition} 

है कि, मैं \[email protected] में \part की मूल परिभाषा बचाने के लिए और है कि प्रयोग करेंगे।

हालांकि, यह तारांकित आदेशों के लिए काम नहीं करता है क्योंकि वे एक ही लेक्समे को परिभाषित नहीं करते हैं (ऊपर दिए गए उदाहरण में \part कमांड के विपरीत)। यह निम्नलिखित प्रश्नों पर उबाल जाता है: मैं एक तारांकित आदेश कैसे सहेज सकता हूं?

ध्यान दें कि suffix पैकेज से \WithSuffix कमांड का उपयोग करके मुझे पहले से ही एक तारांकित आदेश को फिर से परिभाषित करने का तरीका पता है। यह समस्या नहीं है।

उत्तर

8

कोई \part* कमांड नहीं है। क्या होता है \part कमांड इसके बाद के अगले चरित्र को देखता है (\@ifstar के साथ) और दो अन्य दिनचर्या में से एक को प्रेषित करता है जो वास्तविक कार्य करता है कि वहां कोई तारांकन है या नहीं।

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=cmdstar

+0

"कोई' \ है भाग * 'आदेश।" - मुझे पता है। :-(अन्यथा मुझे यह समस्या नहीं होगी। –

+0

तो फिर आपके पास \ \ part' को दोबारा परिभाषित करें और दोनों संस्करणों को संभालें? या लाटेक्स स्रोत में खोदें और अंतर्निहित तारांकित-'\ part' कोड को फिर से परिभाषित करें? –

+0

... लेकिन यह महत्वपूर्ण संकेत था। मुझे अब यह काम मिल गया है। जल्द ही समाधान पोस्ट करेंगे। –

3

@ SMG के जवाब देने के लिए धन्यवाद, मैं एक साथ एक समाधान है कि पूरी तरह से काम करता है पत्थर है। यहाँ पूरा स्रोत है, व्याख्यात्मक टिप्पणी के साथ:

% If this is in *.tex file, uncomment the following line. 
%\makeatletter 

% Save the original \part declaration 
\let\[email protected]\part 

% To that definition, add a new special starred version. 
\WithSuffix\def\part*{ 
    % Handle the optional parameter. 
    \ifx\next[% 
    \let\next\[email protected]@star% 
    \else 
    \def\next{\[email protected]@star[]}% 
    \fi 
    \next} 

% The actual macro definition. 
\def\[email protected]@star[#1]#2{ 
    \ifthenelse{\equal{#1}{}} 
    {% If the first argument isn’t given, default to the second one. 
    \def\[email protected]@short{#2} 
    % Insert the actual (unnumbered) \part header. 
    \[email protected]*{#2}} 
    {% Short name is given. 
    \def\[email protected]@short{#1} 
    % Insert the actual (unnumbered) \part header with short name. 
    \[email protected]*[#1]{#2}} 

    % Last, add the part to the table of contents. Use the short name, if provided. 
    \addcontentsline{toc}{part}{\[email protected]@short} 
} 

% If this is in *.tex file, uncomment the following line. 
%\makeatother 

(। इस पैकेज की जरूरत है suffix और ifthen)

अब, हम इसका इस्तेमाल कर सकते हैं:

\part*{Example 1} 
This will be an unnumbered part that appears in the TOC. 

\part{Example 2} 
Yes, the unstarred version of \verb/\part/ still works, too. 
संबंधित मुद्दे