2

How to make the below \NewDocumentEnvironment 3rd argument optional verbatim (optional that escapes special LaTeX characters)?

Below is the 3 ways for how to the custom style: (Keep in mind that the below code is for [mmoo] not for [mmvo] and you need to escape each character to render successfully)

\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}

This is a follow up question from this question.

6
  • 1
    you are again showing only snippets that one can't compile directly. Commented Aug 3, 2023 at 9:02
  • Will edit it now Commented Aug 3, 2023 at 9:06
  • 1
    Note that we don't need any of your 'payload' to illustrate the core question
    – Joseph Wright
    Commented Aug 3, 2023 at 9:08
  • Hope the edit is up to your standards this time. Commented Aug 3, 2023 at 9:27
  • 1
    why are you using a custom class that one would have to store first? Make a short self contained example based on article and remove all the stuff not needed for the core question. Commented Aug 3, 2023 at 9:42

1 Answer 1

1

Here, I use the tokcycle package to massage argument #3 into a more usable form. As it stands, it can handle #, \, and $ characters. Changes may be needed to the \Characterdirective to handle other special characters. (if you tell me what is needed, I can add/test for them).

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .