phfaist / pylatexenc

Simple LaTeX parser providing latex-to-unicode and unicode-to-latex conversion
https://pylatexenc.readthedocs.io
MIT License
283 stars 35 forks source link

Temporarily disable environment parsing #101

Open Fireblossom opened 10 months ago

Fireblossom commented 10 months ago

Hi, I am trying to parse package files .sty or class files .cls. I noticed that these files contain only macro commands. But the parser may return a None nodelist, because of the unclosed environment.

As seen in the following example from mdpi.cls, there exist two \end{flushleft} with \ifthenelses. So I am writing to ask if there is any switch to disable environment parsing in .cls, so that the parser can ignore the environment.

\renewcommand{\@maketitle}{
    \ifthenelse{\equal{\@arttype}{Book}}{}{
        \ifthenelse{\equal{\@leftcolumnsplit}{\@empty}}{% Default option for the left column
            \marginnote[\contentleftcolumn]{}[\MyLen] % Bottom aligned
            }{%
        }
        \begin{adjustwidth}{-\extralength}{}
    }
    \begin{flushleft}
    \ifthenelse{\equal{\@arttype}{Supfile}}{%
        \fontsize{18}{18}\selectfont
        \raggedright
        \hyphenpenalty=10000
        \tolerance=1000
        \noindent\textbf{Supplementary Materials: \@Title}%
        \par
        \vspace{12pt}
        \fontsize{10}{10}\selectfont
        \noindent\boldmath\bfseries{\@Author}
        }{%
        \ifthenelse{\equal{\@arttype}{Book}}{}{%
            \vspace*{-1.75cm}
        }
        {%0
        \ifthenelse{\equal{\@journal}{preprints}
            \OR \equal{\@arttype}{Book}}{}{%
                \ifthenelse{\equal{\@status}{submit}}{% 
                    \hfill \href{https://www.mdpi.com}{%
                    \includegraphics[height=1cm]{Definitions/logo-mdpi.eps}}%
                    }{
                    \href{https://www.mdpi.com/journal/\@journal}{
                    \includegraphics[height=1.2cm]{Definitions/\@journal-logo.eps}}%
                    \hfill
                    \ifthenelse{\equal{\@journal}{scipharm}}{%
                        \href{https://www.mdpi.com}{\includegraphics[height=1cm]{Definitions/logo-mdpi-scipharm.eps}}%
                        }{%
                        \href{https://www.mdpi.com}{\includegraphics[height=1cm]{Definitions/logo-mdpi.eps}}%
                        }%
                    }%
                    \par
                    \vspace{-8 pt}
                    \rule{\fulllength}{0.4pt}%
            }%
        \par
        }%0
        {%1
            \vspace{14pt}
            \fontsize{10}{10}\selectfont
        \ifthenelse{\equal{\@arttype}{Book}}{}{
            \textit{\@arttype}%
            }%  
        \par%
            }%1
            {%2
        \fontsize{18}{18}\selectfont
        \hyphenpenalty=10000
        \tolerance=1000
        \boldmath\bfseries{\@Title}
        \par
        \vspace{12pt}
        }%2
        \ifthenelse{\equal{\@longauthorlist}{\@empty}}{%
            }{%
            \end{flushleft}%
            \end{adjustwidth}%
            \vspace{-2.5pt}
        }
        {%3
        \hyphenpenalty=10000
        \tolerance=1000
            \boldmath\bfseries{\@Author}
            \par
        \vspace{12pt}
            }%3
        }%
    \ifthenelse{\equal{\@longauthorlist}{\@empty}}{%
        \end{flushleft}%
        }{%
    }%
    \ifthenelse{\equal{\@arttype}{Book}}{}{%
        \ifthenelse{\equal{\@longauthorlist}{\@empty}}{%
            \end{adjustwidth}%
            }{%
        }
    }
        \ifthenelse{\equal{\@leftcolumnsplit}{\@empty}}{% Left column split
            }{
            \marginnote[\contentleftcolumn]{}% Alignment with the affiliations
        }
    }
Fireblossom commented 10 months ago

or maybe support ifthen package's behavior, namely ignore the closing of the environment within a macro's argument. :)