1

I am writing a thesis, and there I have three files, one is main, another one is Chapter and the last one is a.tex.

  • main.tex is using to call the chapter.
  • I have written main algorithm in a.tex. So I am calling that file in chapter.tex. But it shows the errors?

Errors

! Missing \endcsname inserted.<to be read again>\ALG@currentblock@0 \State
! Extra \endcsname.\ALG@makebeginrepeat ...\ALG@thisblock \endcsname\relax \def \ALG@thisblock... \State
! LaTeX Error: Lonely \item--perhaps a missing list environment.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \State
! Missing \endcsname inserted.<to be read again>\ALG@currentblock@0 \State
! Extra \endcsname.\ALG@makebeginrepeat ...\ALG@thisblock \endcsname\relax \def \ALG@thisblock... \State
! LaTeX Error: Lonely \item--perhaps a missing list environment.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \State
! Missing \endcsname inserted.<to be read again>\ALG@currentblock@0 \State
! Extra \endcsname.\ALG@makebeginrepeat ...\ALG@thisblock \endcsname\relax \def \ALG@thisblock... \State
! LaTeX Error: Lonely \item--perhaps a missing list environment.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \State
! Missing \endcsname inserted.<to be read again>\ALG@currentblock@0 \State
! Extra \endcsname.\ALG@makebeginrepeat ...\ALG@thisblock \endcsname\relax \def \ALG@thisblock... \State
! LaTeX Error: Lonely \item--perhaps a missing list environment.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \State
! Missing \endcsname inserted.<to be read again>\ALG@currentblock@0 \State
! Extra \endcsname.\ALG@makebeginrepeat ...\ALG@thisblock \endcsname\relax \def \ALG@thisblock... \State
! Missing \endcsname inserted.<to be read again>\ALG@currentblock@0 \Procedure

Package:

\documentclass[
11pt, % The default document font size, options: 10pt, 11pt, 12pt
%oneside, % Two side (alternating margins) for binding by default, uncomment to switch to one side
english, % ngerman for German
singlespacing, % Single line spacing, alternatives: onehalfspacing or doublespacing
%draft, % Uncomment to enable draft mode (no pictures, no links, overfull hboxes indicated)
%nolistspacing, % If the document is onehalfspacing or doublespacing, uncomment this to set spacing in lists to single
%liststotoc, % Uncomment to add the list of figures/tables/etc to the table of contents
%toctotoc, % Uncomment to add the main table of contents to the table of contents
%parskip, % Uncomment to add space between paragraphs
%nohyperref, % Uncomment to not load the hyperref package
headsepline, % Uncomment to get a line under the header
%chapterinoneline, % Uncomment to place the chapter title next to the number on one line
%consistentlayout, % Uncomment to change the layout of the declaration, abstract and acknowledgements pages to match the default layout
]{MastersDoctoralThesis}
\usepackage{algorithm}
\usepackage{algpseudocode}

a.tex (Code file)

\usepackage{algorithm}
\usepackage{algpseudocode}
%\begin{filecontents}{a.tex}
\begin{algorithm}[H]
%\SetAlgoLined
%\KwResult{Write here the result }
\State $a$ is BAC , $T$ is trignotmatric, $R\textsubscript{Data}$ is my symbolic data\;
\State RS \textsubscript{Data} is textual data\;
\begin{algorithmic}[1]
\State $R\textsubscript{Data} \gets hi$ w.r.t $j$ \Comment{ABC} \;
\State $L_i \gets $ FSC \Comment(i=1,2,3)\;
\State Remove ABC\;
\State $T_{0}\gets R_{Data}$.$T$($start$)\;
$T_{new}$}
\Procedure {multi} {$ab\textsubscript{Data}$, $g\textsubscript{i}$}
          \For {$s\gets RS_{dd}(1)$ \TO $RS_{aa}(end)$} 
           \State $ff_{sw}\gets S_{ddd} \times W_{L}$ 
               \If{vvvv }
                  \State np such 
               \Else 
                 \State $dd_{ss}\gets sss_{ffff} \times aada_{sadada} \times \frac{O_{LP}}{100}$ 

               \EndIf
               \For {$F_{S}\gets 1 \leq 6$}
                    \State $E_{feature}\gets F(T_{sw}
               \EndFor
          \EndFor
\EndProcedure

\Procedure {myz}{$sa_{aa}$}
                \For {each value}
                   \State Not something 
                \EndFor
\EndProcedure
 \caption{MYALGORIHTM}
 \end{algorithmic}
\end{algorithm}
%\end{filecontents}

Please help me out to this problem?

  • You have to wrap your first two states into the algorithmic environment, too. The given code would not work nevertheless: Without amsmath the \; at the end of the lines (which are not needed at all as there is no text afterwards) throws an error, you have an extra } in $T_{new}$} (which seems to miss something like \State beforehand, too), \TO is undefined and $E_{feature}\gets F(T_{sw} is missing the end of the math mode. – epR8GaYuh Apr 25 at 9:41
  • Same code is working in other latex file but here its not working. – Nafees Ahmed Apr 25 at 10:18
  • 1
    Sorry, but your code for the algorithmn can not work. See my answer for a corrected code for the algorithmn ... – Mensch Apr 25 at 19:22
2

Sorry, but your question is nearly the same you asked before, where I already gave you an answer: old question with my answer

In this answer I already told you to -- for example -- change $ \TO $ to correct \to etc.

I do not have your used class MastersDoctoralThesis but I know it is sayed to be very problematic. So if you can not test it yourself please add a link to that class you used in your question.

For this answer I simply use article.

Please see this corrected code

\documentclass{article}

\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\State $a$ is BAC , $T$ is trignotmatric, $R\textsubscript{Data}$ is my symbolic data%\;
\State RS \textsubscript{Data} is textual data%\;
\State $R\textsubscript{Data} \gets hi$ w.r.t $j$ \Comment{ABC} %\;
\State $L_i \gets $ FSC \Comment(i=1,2,3)%\;
\State Remove ABC%\;
\State $T_{0}\gets R_{Data}$.$T$($start$)%\;
%$T_{new}$}
\Procedure {multi} {$ab\textsubscript{Data}$, $g\textsubscript{i}$}
  \For {$s\gets RS_{dd}(1) \to RS_{aa}(end)$} % <============= \TO -> \to inside $ $
    \State $ff_{sw}\gets S_{ddd} \times W_{L}$ 
    \If{vvvv }
      \State np such 
    \Else 
      \State $dd_{ss}\gets sss_{ffff} \times aada_{sadada} \times \frac{O_{LP}}{100}$ 
    \EndIf
    \For {$F_{S}\gets 1 \leq 6$}
      \State $E_{feature}\gets F(T_{sw}$ % <==============
    \EndFor
  \EndFor
\EndProcedure

\Procedure {myz}{$sa_{aa}$}
                \For {each value}
                   \State Not something 
                \EndFor
\EndProcedure
 \caption{MYALGORIHTM}
 \end{algorithmic}
\end{algorithm}
\end{document}

and its result:

resulting algorithmn

Please see that I once again commented your wrong \; at the end od the first \State lines of you. I already did that in your old question.

Please study given answers and learn from them!

  • Yes, its work. Thank you so much for your help. – Nafees Ahmed Apr 26 at 9:38

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.