0

I am trying to create a pagestyle, where \guideNameA is mandatory and if \guideNameB is used then I want modify the page style accordingly. Also I need to modify the document content by checking whether I used \stuNameB is used in preamble. The following is page style

\ProvidesPackage{Title}[2020/01/11 v.01 an example package]
\RequirePackage{graphicx}
\RequirePackage{tikz}

\newcommand*{\guideNameA}[1]{\gdef\@guideNameA{#1}}
\newcommand*{\@guideNameA}{\texttt{\string\guideNameA} currently not set. Please fix this.}
\newcommand*{\guideNameB}[1]{\gdef\@guideNameA{#1}}
\newcommand*{\@guideNameB}{}

\newcommand*{\stuNameA}[1]{\gdef\@stuNameA{#1}}
\newcommand*{\@stuNameA}{\texttt{\string\stuNameA} currently not set. Please fix this.}
\newcommand*{\stuUSNA}[1]{\gdef\@stuUSNA{#1}}
\newcommand*{\@stuUSNA}{\texttt{\string\stuUSNA} currently not set. Please fix this.}
\newcommand*{\stuNameB}[1]{\gdef\@stuNameB{#1}}
\newcommand*{\@stuNameB}{}
\newcommand*{\stuUSNB}[1]{\gdef\@stuUSNB{#1}}
\newcommand*{\@stuUSNB}{}
\newcommand*{\stuNameC}[1]{\gdef\@stuNameC{#1}}
\newcommand*{\@stuNameC}{}
\newcommand*{\stuUSNC}[1]{\gdef\@stuUSNC{#1}}
\newcommand*{\@stuUSNC}{}

\renewcommand*{\maketitle}{%
\begin{titlepage}
\begin{tikzpicture}[remember picture, overlay]
  \draw[line width = 4pt] ($(current page.north west) + (0.75in,-0.75in)$) rectangle ($(current page.south east) + (-0.75in,0.75in)$);
\end{tikzpicture}
\begin{center}

\vspace{1cm}
{\Large\bfseries\@title\unskip\strut\par}
\vspace{0.25cm}
{\Large\bfseries\ PROJECT REPORT\unskip\strut\par}
\vspace{0.25cm}
{\Large\bfseries Submitted by,\unskip\strut\par}
\end{center}
{\noindent\large\bfseries\@stuNameA\unskip\strut}\hfill{\large\bfseries\@stuUSNA\unskip\strut\par}
\vspace{0.25cm}
{\noindent\large\bfseries\@stuNameB\unskip\strut}\hfill{\large\bfseries\@stuUSNB\unskip\strut\par}
\vspace{0.25cm}
{\noindent\large\bfseries\@stuNameC\unskip\strut}\hfill{\large\bfseries\@stuUSNC\unskip\strut\par}
\begin{center}
{\Large\bfseries Under the guidance of \unskip\strut\par}
\end{center}

%%%%%%Check if \guideNameB is used%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%If true %%%%%%%%%%%%%
{\noindent\large\bfseries\@guideNameA\unskip\strut}\hfill{\large\bfseries\@guideNameB\unskip\strut\par}

%%%%%%%%%%%%%Else %%%%%%%%%%%%%%%%%
\begin{center}
{\large\bfseries\@guideNameA\unskip\strut\par}
\end{center}
\end{titlepage}
}
\endinput

and the document is

\documentclass{book}
%Packages
\usepackage{Title}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[a4paper, margin=1in]{geometry}

%%%%%%%%%%%%%%% Commands used from "Title" %%%%%%%%%% 
\stuNameA{P Narashimaraja}
\stuUSNA{1RV07EC007}
\stuNameB{Nithin M}
\stuUSNB{1RV14EC001}

\guideNameA{Narashimaraja}
\guideNameB{Ramavenkateshwaran}

\begin{document}
\maketitle

%%%%%%%%%%%%%%%%%%%If \stuNameB{} command is used, then %%%%%%%%%%%%%%
Certified that the major project work titled \textbf{\textit{TITLE}} is carried out by \textbf{STUDENT NAME A} **and \textbf{STUDENT NAME B}**  who **are** bonafide students of College of Engineering
%%%%%%%%%%%%%%%%%%%%%Else %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Certified that the major project work titled \textbf{\textit{TITLE}} is carried out by \textbf{STUDENT NAME A} who **is** bonafide students of College of Engineering

\end{document}

0

You can use TeX's \newif macro to define booleans. After \newif\iffoo, the boolean can be set using \footrue or \foofalse, and tested using \iffoo ... \else ... \fi. Beware that setting booleans respects the grouping rules of TeX: unless preceded by \global, such a setting is local to the innermost group. Applying this to your code, I did the following (this includes additions that you didn't mention in your question but seem to desire, as I understood from the comments):

% Title.sty
...
\newif\ifGuideNameBUsed         % initial state: false
\newif\ifStuNameBUsed           % ditto
...
\newcommand*{\guideNameB}[1]{\gdef\@guideNameB{#1}\global\GuideNameBUsedtrue}
...
\newcommand*{\stuNameB}[1]{\gdef\@stuNameB{#1}\global\StuNameBUsedtrue}
...
\renewcommand*{\maketitle}{%
  \begin{titlepage}
    ...
    \ifGuideNameBUsed
      ...
    \else
      ...
    \fi
    \vfill
    \CollegeCertification
  \end{titlepage}%
}

\newcommand*{\CollegeCertification}{%
  ...
  \ifStuNameBUsed
    ...
  \else
    ...
  \fi
}

Student document:

\documentclass{book}
\usepackage{Title}
...

\title{The Foo Project}

\stuNameA{P.~Duckafoo}
...
\guideNameA{Prof.~Prof.~Canard}
...

\begin{document}
\maketitle

Student text goes here.

\end{document}

I fixed this line from your Title.sty:

\newcommand*{\guideNameB}[1]{\gdef\@guideNameA{#1}}

which defines or overwrites \@guideNameA instead of \@guideNameB. I also fixed the “students” (extra s in the single student case) at the end of your sample document. Additionally, tikz, its calc library and the graphicx package can be required from the Title package code; there is no need to pollute the preamble of student documents with this, as the \usepackage{Title} line will automatically do what is needed (a better name for the package, more specific to the College structure where this package is used, would be a good idea IMHO...). Here is the complete code:

Title.sty:

\ProvidesPackage{Title}[2020/01/24 v0.1 An example package]
\RequirePackage{graphicx}
\RequirePackage{tikz}
\usetikzlibrary{calc}

\newif\ifGuideNameBUsed         % initial state: false
\newif\ifStuNameBUsed           % ditto

\newcommand*{\guideNameA}[1]{\gdef\@guideNameA{#1}}
\newcommand*{\@guideNameA}{\texttt{\string\guideNameA} currently not set. Please fix this.}
\newcommand*{\guideNameB}[1]{\gdef\@guideNameB{#1}\global\GuideNameBUsedtrue}
\newcommand*{\@guideNameB}{}

\newcommand*{\stuNameA}[1]{\gdef\@stuNameA{#1}}
\newcommand*{\@stuNameA}{\texttt{\string\stuNameA} currently not set. Please fix this.}
\newcommand*{\stuUSNA}[1]{\gdef\@stuUSNA{#1}}
\newcommand*{\@stuUSNA}{\texttt{\string\stuUSNA} currently not set. Please fix this.}
\newcommand*{\stuNameB}[1]{\gdef\@stuNameB{#1}\global\StuNameBUsedtrue}
\newcommand*{\@stuNameB}{}
\newcommand*{\stuUSNB}[1]{\gdef\@stuUSNB{#1}}
\newcommand*{\@stuUSNB}{}
\newcommand*{\stuNameC}[1]{\gdef\@stuNameC{#1}}
\newcommand*{\@stuNameC}{}
\newcommand*{\stuUSNC}[1]{\gdef\@stuUSNC{#1}}
\newcommand*{\@stuUSNC}{}

\renewcommand*{\maketitle}{%
  \begin{titlepage}
  \begin{tikzpicture}[remember picture, overlay]
    \draw[line width = 4pt]
      ($(current page.north west) + (0.75in,-0.75in)$) rectangle
      ($(current page.south east) + (-0.75in,0.75in)$);
  \end{tikzpicture}
  \begin{center}

  \vspace{1cm}
  {\Large\bfseries\@title\unskip\strut\par}
  \vspace{0.25cm}
  {\Large\bfseries\ PROJECT REPORT\unskip\strut\par}
  \vspace{0.25cm}
  {\Large\bfseries Submitted by,\unskip\strut\par}
  \end{center}
  {\noindent\large\bfseries\@stuNameA\unskip\strut}\hfill{\large\bfseries\@stuUSNA\unskip\strut\par}
  \vspace{0.25cm}
  {\noindent\large\bfseries\@stuNameB\unskip\strut}\hfill{\large\bfseries\@stuUSNB\unskip\strut\par}
  \vspace{0.25cm}
  {\noindent\large\bfseries\@stuNameC\unskip\strut}\hfill{\large\bfseries\@stuUSNC\unskip\strut\par}
  \begin{center}
  {\Large\bfseries Under the guidance of \unskip\strut\par}
  \end{center}

  \ifGuideNameBUsed
    {\noindent\large\bfseries\@guideNameA\unskip\strut}%
    \hfill
    {\large\bfseries\@guideNameB\unskip\strut\par}%
  \else
    \begin{center}
    {\large\bfseries\@guideNameA\unskip\strut\par}%
    \end{center}%
  \fi
  \vfill
  \CollegeCertification
  \end{titlepage}%
}

\newcommand*{\CollegeCertification}{%
  \noindent
  \ifStuNameBUsed
    Certified that the major project work titled \textbf{\textit{\@title}} is
    carried out by \textbf{\@stuNameA} and \textbf{\@stuNameB} who are
    \emph{bonafide} students of College of Engineering.
  \else
    Certified that the major project work titled \textbf{\textit{\@title}} is
    carried out by \textbf{\@stuNameA} who is a \emph{bonafide} student of
    College of Engineering.
  \fi
}

\endinput

Sample student document:

\documentclass{book}
\usepackage{Title}
\usepackage[a4paper, margin=1in]{geometry}

\title{The Foo Project}

\stuNameA{P.~Duckafoo}
\stuUSNA{1RV07EC007}
\stuNameB{Q.~Quack}
\stuUSNB{1RV14EC001}

\guideNameA{Prof.~Prof.~Canard}
\guideNameB{Prof.~Dr.~Poulet~Jr.}

\begin{document}
\maketitle
\end{document}

I have to say I'm not a big fan of the very thick frame and the \large\bfseries type in the title page... Anyway, here are screenshots for the four possible cases:

  • One supervisor, one student:

enter image description here

  • One supervisor, two students:

enter image description here

  • Two supervisors, one student:

enter image description here

  • Two supervisors, two students:

enter image description here

Answer to your last request

Answer to this comment. At the end of Title.sty, right before \endinput, add:

\newcommand*{\printStuNameA}{\leavevmode\@stuNameA}
\newcommand*{\printStuNameB}{\leavevmode\@stuNameB}

In the student document, you can then use the \CollegeCertification macro or something like this:

\ifStuNameBUsed
  Two students: \printStuNameA\ and \printStuNameB.
\else
  Only one student: \printStuNameA.
\fi

If you don't want the last thing I included in the title page, simply remove the line containing \CollegeCertification before \end{titlepage} in Title.sty.

  • I need the STUDENT NAME to be substituted from \stuNameA{} and \stuNameB{} commands that I have defined before. Can I use, \@stuNameA, but this can only be used only inside package I belive. So is there is any alternative way to get it? – Raja Jan 24 at 18:23
  • Not necessarily, as \makeatletter can be used outside the package. But why don't you write a command inside the package that produces the text from the end of the document, that contains the \ifStuNameBUsed test plus text with \@stuNameA and \@stuNameB? – frougon Jan 24 at 19:05
  • @Raja Please check the latest version of the answer. I tried to guess what you want and applied the suggestion I made in the previous comment. – frougon Jan 24 at 20:15
  • I need \stuNameA to be used as a content in another page, not on the title page itself. Some how need to use \stuNameA and B anywhere inside the document, which where defined in the preamble. – Raja Jan 25 at 2:06
  • @Raja Please see the edited answer. – frougon Jan 25 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.