'if'-'then'-'else'를 사용하여 LaTex 명령을 어떻게 작성합니까?

'if'-'then'-'else'를 사용하여 LaTex 명령을 어떻게 작성합니까?

나는 읽었다LaTeX \if 조건그리고알고리즘에 if와 then을 작성하는 방법은 무엇입니까?, 그러나 지금까지는 나에게 종소리가 울리지 않았습니다.

다음과 같은 명령을 만들려고 합니다.점선기술아래처럼. 그 뒤에 있는 논리는 다음과 같습니다.

  • 두 개의 매개변수를 받습니다
  • 카운터 x를 1에서 #2까지 반복합니다.
  • 채워진 카운터가 0보다 큰 경우 전체 점을 그리고 카운터를 감소시킵니다.
  • 그렇지 않으면 빈 점을 그립니다.
\newcommand{\dottedSkill}[2]{
    %parameter 1 the filled dots
    %parameter 2 the max dots

    \newcounter{x}
    \newcounter{filled}
    \setcounter{filled}{#1}
    \forloop{x}{1}{\value{x} <= #2}
    {
        \ifnum \filled<1
            \Circle
        \else
            \CIRCLE
            \addtocounter{filled}{-1}
        \fi
    }
}%

문제가 명령 정의에 있는지 아니면 다른 곳에 있는지 확실하지 않지만 파일에서 호출하면 다음과 같은 결과가 나타납니다.

  • 정의되지 않은 제어 순서. \dottedSkill{2}{9}.
  • 숫자가 누락되어 0으로 처리됩니다. \dottedSkill{2}{9}
  • 정의되지 않은 제어 순서. \dottedSkill{2}{9}.
  • 숫자가 누락되어 0으로 처리됩니다. \dottedSkill{2}{9}

내 함수가 올바르게 작성되었나요?

답변1

현재 설정의 문제는filled .모든당신이 달리는 시간 \dottedSkill. 명령에서 이러한 정의를 가져와야 합니다 \dottedSkill.

또한, 채워진 원을 그린 다음 빈 원을 그려야 합니다.

여기에 이미지 설명을 입력하세요

\documentclass{article}

\usepackage{multido}

\newcommand{\Circle}{\textbullet}
\newcommand{\CIRCLE}{$\circ$}

\newcommand{\dottedSkill}[2]{%
  %parameter 1 the filled dots
  %parameter 2 the max dots  
  \multido{\ix=1+1}{#1}{\Circle}%
  \ifnum#1<#2 \multido{\ix=#1+1}{\numexpr#2-#1}{\CIRCLE}\fi
}%

\begin{document}

\dottedSkill{2}{9}

\dottedSkill{0}{9}

\dottedSkill{10}{9}

\dottedSkill{5}{9}

\end{document}

multido비슷한 작품forloop일부 값을 반복합니다.

답변2

\documentclass{article}
\usepackage{forloop}
\newcounter{x}
\newcounter{filled}
\newcommand{\dottedSkill}[2]{%
    %parameter 1 the filled dots
    %parameter 2 the max dots
    \setcounter{filled}{#1}%
    \forloop{x}{0}{\value{x} < #2}%
    {%
        \ifnum \thefilled < 1 
            $\circ$%\Circle
        \else 
            $\bullet$%\CIRCLE 
            \addtocounter{filled}{-1}%
        \fi
    }%
}%
\begin{document}
\dottedSkill{2}{9}
\end{document}

여기에 이미지 설명을 입력하세요

답변3

조건문이 정말로 필요한지 나에게 첫 번째 질문입니다. XY 문제의 경우에만(실제 문제는 루프를 작동시키는 것이 아니라 두 개의 인수가 있는 매크로로 점수를 만드는 것입니다) 여기에 더 간단한 접근 방식이 있습니다.

음

\documentclass{article}
\newcommand\score[2][10]{
\makebox[#2em]{\cleaders\hbox to 1em{\Large\hss$\bullet$\hss}\hfill}%
\makebox[\dimexpr#1em-#2em]{\cleaders\hbox to 1em{\Large\hss$\circ$\hss}\hfill}\par} 
\begin{document}
\score[5]{0} 
\score[5]{1}
\score[5]{3}
\score[5]{5}
\score{0} 
\score{3} 
\score{6}
\score{10}
\end{document}

답변4

여러분 덕분에 이에 대한 솔루션을 세부적으로 조정할 수 있었습니다.

나는 이 링크를 원 유형에 대한 참조로 사용했습니다.https://aneescraftsmanship.com/circle-symbols%E2%97%8B%E2%97%8F%E2%97%8D%E2%97%97%E2%97%94%E2%97%99%E2% A6%BF-in-라텍스/

\usepackage{wasysym}

\newcommand{\EmptyDot}{\Circle}
\newcommand{\FilledDot}{$\CIRCLE$}

\newcommand{\dottedSkill}[2]{%
    %parameter 1 the filled dots
    %parameter 2 the max dots  
    \multido{\ix=1+1}{#1}{\FilledDot}%
    \ifnum#1<#2 \multido{\ix=#1+1}{\numexpr#2-#1}{\EmptyDot}\fi
}%

관련 정보