如何在我的 \NewDocumentEnvironment 中使逐字选项成为可选项?

如何在我的 \NewDocumentEnvironment 中使逐字选项成为可选项?

如何使下面的\NewDocumentEnvironment第三个参数逐字可选(可选,转义特殊的 LaTeX 字符)?

以下是自定义样式的 3 种方法:(请记住,以下代码不适用于[mmoo][mmvo]您需要转义每个字符才能成功呈现)

\documentclass[11pt,letterpaper]{article} % Use the custom resume.cls style

\usepackage[left=0.4 in,top=0.4in,right=0.4 in,bottom=0.4in]{geometry} % Document margins

\usepackage[parfill]{parskip} % Remove paragraph indentation
\usepackage{array} % Required for boldface (\bf and \bfseries) tabular columns
\usepackage{ifthen} % Required for ifthenelse statements

\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,      
    urlcolor=blue,
}
\usepackage{xparse} % For Projects Formatting

\pagestyle{empty} % Suppress page numbers


%----------------------------------------------------------------------------------------
%   SECTION FORMATTING
%----------------------------------------------------------------------------------------

% Defines the rSection environment for the large sections within the CV
\newenvironment{rSection}[1]{ % 1 input argument - section name
  \sectionskip
  \MakeUppercase{
    %\small %I personally wrote it for testing purposes
    {\bf #1}} % Section title
  \sectionlineskip
  \hrule % Horizontal line
  \begin{list}{}{ % List for each individual item in the section
    \setlength{\leftmargin}{0em} % Margin within the section
    %\small %I personally wrote it for testing purposes
  }
  \item[]
}{
  \end{list}
}

%----------------------------------------------------------------------------------------
%   Projects FORMATTING
%----------------------------------------------------------------------------------------

\NewDocumentEnvironment{rProjects}{mmoo}{ % 2 mandatory arguments and 2 optional argument, project name, project description, project link, link name
 \textbf{#1}. {#2} % Bold project name then description
 \IfValueT{#3}{
  \ifthenelse{\equal{#4}{}} % Project Link & Name
  {\hfill \href{#3}{GitHub Link}}
  {\hfill \href{#3}{#4}}

 }\smallskip
}{}


%----------------------------------------------------------------------------------------
%   Itemize FORMATTING
%----------------------------------------------------------------------------------------

\newenvironment{rItemize}{\begin{itemize}
  \raggedright
  \itemsep 0pt {}
  %\small
  %\parskip 0pt {}
}
{\end{itemize}}


%----------------------------------------------------------------------------------------
% The below commands define the whitespace after certain things in the document - they can be \smallskip, \medskip or \bigskip
\def\sectionlineskip{\medskip} % The space above the horizontal line for each section 
\def\sectionskip{\medskip} % The space after the heading section

\begin{document}

\begin{rSection}{PROJECTS}
    
    \begin{rProjects}{Project name}{description}
        \begin{rItemize}
            \item Achieved X\% growth for XYZ using A, B, and C skills.
            \item Led XYZ which led to X\% of improvement in ABC.
            \item Developed XYZ that did A, B, and C using X, Y, and Z.
        \end{rItemize}
    \end{rProjects}

    \begin{rProjects}{Project name}{description.}[https://github.com/OmarShawky1/CS-Roadmap\#projects][]
        \begin{rItemize}
            \item Achieved X\% growth for XYZ using A, B, and C skills.
            \item Led XYZ which led to X\% of improvement in ABC.
            \item Developed XYZ that did A, B, and C using X, Y, and Z.
        \end{rItemize}
    \end{rProjects}

    \begin{rProjects}{Project name}{description}[https://github.com/OmarShawky1/CS-Roadmap\#projects][Project Link]
        \begin{rItemize}
            \item Achieved X\% growth for XYZ using A, B, and C skills.
            \item Led XYZ which led to X\% of improvement in ABC.
            \item Developed XYZ that did A, B, and C using X, Y, and Z.
        \end{rItemize}
    \end{rProjects}

\end{rSection}

\end{document}

这是来自这个问题

答案1

在这里,我使用tokcycle包将参数调整#3为更可用的形式。就目前而言,它可以处理#\$字符。可能需要对进行更改以\Characterdirective处理其他特殊字符。(如果您告诉我需要什么,我可以添加/测试它们)。

\documentclass[11pt,letterpaper]{article} % Use the custom resume.cls style
\usepackage[T1]{fontenc}
\usepackage[left=0.4 in,top=0.4in,right=0.4 in,bottom=0.4in]{geometry} % Document margins

\usepackage[parfill]{parskip} % Remove paragraph indentation
\usepackage{array} % Required for boldface (\bf and \bfseries) tabular columns
\usepackage{ifthen} % Required for ifthenelse statements
\usepackage{tokcycle}
%\Characterdirective{...}% may be needed for other special characters
\Macrodirective{\addcytoks[1]{\string#1}}% needed for backslash

\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,      
    urlcolor=blue,
}
\usepackage{xparse} % For Projects Formatting

\pagestyle{empty} % Suppress page numbers


%----------------------------------------------------------------------------------------
%   SECTION FORMATTING
%----------------------------------------------------------------------------------------

% Defines the rSection environment for the large sections within the CV
\newenvironment{rSection}[1]{ % 1 input argument - section name
  \sectionskip
  \MakeUppercase{
    %\small %I personally wrote it for testing purposes
    {\bf #1}} % Section title
  \sectionlineskip
  \hrule % Horizontal line
  \begin{list}{}{ % List for each individual item in the section
    \setlength{\leftmargin}{0em} % Margin within the section
    %\small %I personally wrote it for testing purposes
  }
  \item[]
}{
  \end{list}
}

%----------------------------------------------------------------------------------------
%   Projects FORMATTING
%----------------------------------------------------------------------------------------

\NewDocumentEnvironment{rProjects}{mmoo}{ % 2 mandatory arguments and 2 optional argument, 
%project name, project description, project link, link name
 \textbf{#1}. {#2} % Bold project name then description
 \IfValueT{#3}{%
  \tokcyclexpress{#3}%
  \ifthenelse{\equal{#4}{}} % Project Link & Name
  {\hfill \expandafter\href\expandafter{\the\cytoks}{GitHub Link}}
  {\hfill \expandafter\href\expandafter{\the\cytoks}{#4}}

 }\smallskip
}{}


%----------------------------------------------------------------------------------------
%   Itemize FORMATTING
%----------------------------------------------------------------------------------------

\newenvironment{rItemize}{\begin{itemize}
  \raggedright
  \itemsep 0pt {}
  %\small
  %\parskip 0pt {}
}
{\end{itemize}}


%----------------------------------------------------------------------------------------
% The below commands define the whitespace after certain things in the document - they can 
% be \smallskip, \medskip or \bigskip
\def\sectionlineskip{\medskip} % The space above the horizontal line for each section 
\def\sectionskip{\medskip} % The space after the heading section

\begin{document}

\begin{rSection}{PROJECTS}
    
    \begin{rProjects}{Project name}{description}
        \begin{rItemize}
            \item Achieved X\% growth for XYZ using A, B, and C skills.
            \item Led XYZ which led to X\% of improvement in ABC.
            \item Developed XYZ that did A, B, and C using X, Y, and Z.
        \end{rItemize}
    \end{rProjects}

    \begin{rProjects}{Project name}{description.}
  [https://github.com/OmarShawky1/CS-Roadmap#projects\subname$][]
        \begin{rItemize}
            \item Achieved X\% growth for XYZ using A, B, and C skills.
            \item Led XYZ which led to X\% of improvement in ABC.
            \item Developed XYZ that did A, B, and C using X, Y, and Z.
        \end{rItemize}
    \end{rProjects}

    \begin{rProjects}{Project name}{description}
  [https://github.com/OmarShawky1/CS-Roadmap#projects][Project Link]
        \begin{rItemize}
            \item Achieved X\% growth for XYZ using A, B, and C skills.
            \item Led XYZ which led to X\% of improvement in ABC.
            \item Developed XYZ that did A, B, and C using X, Y, and Z.
        \end{rItemize}
    \end{rProjects}

\end{rSection}

\end{document}

在此处输入图片描述

相关内容