-1

I am getting frustrated. I am trying to use int, mod, floor functions and even Mod in LaTeX, but I always get a undefined control sequence error. I have included the following packages:

\usepackage{pgfmath}
\usepackage{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{xparse}
\usepackage{amsmath}
\usepackage{xstring}
\usepackage{tikz}
\usepackage{ifthen}

I also tried using:

\usepackage{pgfmath-xfp}

I don't get any error in relation to the package itself. If I try to load a package that doesn't exist I get the following error:

\usepackage{foobar}

! LaTeX Error: File `foobar.sty' not found.

Type X to quit or to proceed, or enter new name. (Default extension: sty)

I tried with Texifier, with the IntelliJ IDEA TeXiFy plugin and I have install Tex Live as well.

This is the code I am using:

% This command is used to display a new job on the timeline. The job is represented by a trapezium.
% #1 - start date (month/year)
% #2 - end date (month/year)
% #3 - level (used in case you want to change the distance from the timeline)
% #4 - trapezium color
% #5 - label (role and company name)
% #6 - opacity of the trapezium
\newcommand\job[6]{
    \setcounter{jobID}{1}

    \StrBefore{#1}{/}[\startMonth] % month in which the job started
    \StrBehind{#1}{/}[\startYear]  % year in which the job started
    \StrBefore{#2}{/}[\endMonth]   % month in which the job ended
    \StrBehind{#2}{/}[\endYear]    % year in which the job ended

    % The start and end dates are expressed as a fraction of the total number of months between the first and last years.
    \pgfmathsetmacro\startAt{(\startYear-\firstYear)+(1/12*(\startMonth-1))}
    \pgfmathsetmacro\endAt{(\endYear-\firstYear)+(1/12*(\endMonth))}

    \pgfmathsetmacro\trapAngle{80}
    \pgfmathsetmacro\maxTrapHeight{35}

    \pgfmathsetmacro\jobDurationMonths{(\endYear - \startYear) * 12 + (\endMonth - \startMonth)}

    % Define the threshold duration (in months) for the two linear segments.
    \pgfmathsetmacro\thresholdDuration{120}

    % Define the scaling factors for the two linear segments.
    \pgfmathsetmacro\shortDurationScale{0.8}
    \pgfmathsetmacro\longDurationScale{0.2}

    % Calculate the scaling factor using the piecewise function.
    \pgfmathsetmacro\scalingFactor{(\jobDurationMonths <= \thresholdDuration) * (\shortDurationScale - (\jobDurationMonths / \thresholdDuration) * (\shortDurationScale - \longDurationScale)) + (\jobDurationMonths > \thresholdDuration) * \longDurationScale}

    % Calculate the trapezium height based on the trapezium width and the duration scaling factor.
    %\pgfmathsetmacro\trapHeight{max(\trapWidth * \scalingFactor, 5)}
    % We set the trapezium width based on the number of months between the start and end dates of the job.
    % The trapezium is rotated 270 degrees, so the width is the height and vice versa.
    % We use a scaling factor to calculate the height of the trapezium. This factor is calculated using a piecewise
    % function, so that the trapeziums never get too wide. I tried using a logarithmic function, and a decay exponential
    % functions but the result wasn't good enough.
    \pgfmathsetmacro\trapWidth{(((\endYear-\startYear)*12)+(\endMonth-\startMonth)+1)}
    \pgfmathsetmacro\trapHeight{max(\trapWidth * \scalingFactor, 5)}

    % Trapezium origin. The trapezium is rotated 270 degrees, so the origin is at the top left corner.
    \pgfmathsetmacro\trapX{(#3)+(\trapHeight/10)}
    \pgfmathsetmacro\trapY{(\startAt+(\endAt-\startAt)/2))}

    % Trapezium middle point. The trapezium is rotated 270 degrees, so the middle point is at the top right corner.
    \pgfmathsetmacro\middleX{\trapX+(\trapHeight/20)-0.1+0.07}
    \pgfmathsetmacro\middleY{\trapY}

    % Draw the trapezium.
    \draw (\trapX,\trapY) node[trapezium, trapezium angle=\trapAngle, trapezium stretches=true, minimum height={\mmtopt{\trapHeight}}, minimum width={\mmtopt{\trapWidth}}, font=\scriptsize, fill=#4!50, opacity={#6}, rotate=270] {};
    \draw[double, fill] (\middleX,\middleY) circle [radius=2pt];

    % Determines the position of the label based on the trapezium height.

    % Calculate the angle based on trapezium height, jobID, and the maximum trapezium height.
    \pgfmathsetmacro\angleForLabelPlacement{70 - 40 * (\trapHeight / \maxTrapHeight) + 20 * (fpeval(int(\jobID) mod 2))}

    % Calculate the length of the first line based on the trapezium height and the maximum trapezium height.
    \pgfmathsetmacro\lineLength{1.5 - (\trapHeight / \maxTrapHeight)}

    % Calculate the offset for the label based on the trapezium height and the maximum trapezium height.
    \pgfmathsetmacro\labelOffset{0.3 * (\trapHeight / \maxTrapHeight)}

    % Calculate the end of the first line based on the adjusted angle, length, and offset.
    \coordinate (startLine) at (\middleX,\middleY);
    \coordinate (endFirstLine) at ([shift=(\angleForLabelPlacement:\lineLength+\labelOffset)]startLine);

    % Draw the label.
    \pgfmathsetmacro\labelPaddingBottom{2pt} % padding between the label and the line
    \node[anchor=south west, font=\tiny,inner sep=0pt, yshift=\labelPaddingBottom] (label) at (endFirstLine) {#5};

    \coordinate (endSecondLine) at (label.east |- endFirstLine);

    \draw (startLine) -- (endFirstLine);
    \draw (endFirstLine) -- (endSecondLine);

    \stepcounter{jobID}
}

To call the function I use:

\job{12/1995}{9/1997}{0}{NavyBlue}{Software Developer}{0.8}
noun
  • 3,635
  • 2
  • 25
  • 27

1 Answers1

0

The issue is that jobID can't be used as int(\jobID). The correct syntax is int(\value{jobID}).

noun
  • 3,635
  • 2
  • 25
  • 27