使用 if / else 设置路径

使用 if / else 设置路径

根据前面的文本,我需要将路径设置为文件夹 1 或文件夹 2。只有一个文件夹时一切正常,但有条件时则不行。我遗漏了什么?

\newcommand{\nc}{text-a}

\ifthenelse{\equal{\nc}{text-a}}
{
    \makeatletter
    \def\input@path{{"../folder-1/"}}
    \makeatother
}{
    \makeatletter
    \def\input@path{{"../folder-2/"}}
    \makeatother
}

编辑:不幸的是,它也不会这样:

\newcommand{\nc}{text-a}

\makeatletter
    \ifthenelse{\equal{\nc}{text-a}}{
       \def\input@path{{"../folder-1/"}}
    }{   \def\input@path{{"../folder-2/"}}
    }
\makeatother

答案1

发布的代码确实有条件地设置了路径,下面的测试文件显示了这两种设置:


LaTeX2e <2018-12-01>
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/ifthen.sty)
> \input@path=macro:
->{"../folder-1/"}.
l.13 \show\input@path

? 
> \input@path=macro:
->{"../folder-2/"}.
l.26 \show\input@path

? 
 )
No pages of output.

\RequirePackage{ifthen}

\newcommand{\nc}{text-a}

\makeatletter
    \ifthenelse{\equal{\nc}{text-a}}{
       \def\input@path{{"../folder-1/"}}
    }{   \def\input@path{{"../folder-2/"}}
    }
\makeatother

\makeatletter
\show\input@path
\makeatother

\renewcommand{\nc}{text-b}

\makeatletter
    \ifthenelse{\equal{\nc}{text-a}}{
       \def\input@path{{"../folder-1/"}}
    }{   \def\input@path{{"../folder-2/"}}
    }
\makeatother

\makeatletter
\show\input@path
\makeatother



\stop

相关内容