0

So I am trying to create a new package for Latex. Currently I have one function like this:

\def\timeline#1#2#3{%
   % draw the timeline
}%

In this function I open the tikz environment with \begin{tikzpicture}. I also have a function which draws a single event into this environment, which can be called multiple times.

Now I am not sure how to close the tikz environment after all events have been added. Can somebody explain this to me?

Currently I have the following code in the sty file:

\newenvironment{cvtimeline}{%
    \begin{tikzpicture}%
}{%
    \end{tikzpicture}%
}%
% Functions
\def\timeline#1#2#3{%
   % draw the timeline
}%

\def\work#1#2#3#4#5{%
   % add an work event and draw
}%
\def\school#1#2#3#4#5{%
   % add an school event and draw
}%

This can be used in a tex file as follows:

\begin{document}
    \begin{cvtimeline}
        \timeline{2009}{2017}{\textwidth}
        \work{2009}{8}{2013}{8}{Hello}
        \work{2013}{10}{2014}{8}{World}
    \end{cvtimeline}
\end{document}
10
  • If you want to create a LaTeX package, you should use LaTeX syntax.
    – Johannes_B
    Feb 18, 2017 at 10:02
  • @Johannes_B and this means?
    – Pascal
    Feb 18, 2017 at 10:03
  • 1
    You can use \newenvironment instead of \def (or \newcommand) to define your timeline: \newenvironment{timeline}[3]{... code to open your environment...}{... code to close you envrionment...} Feb 18, 2017 at 10:27
  • 1
    In my opinion the command \timeline is defined according to LaTeX syntax. It is defined using \def which is TeX, but considering that the majority of packages uses this convention I don't see a major problem, as long as you are sure that the command is not earlier defined. But it could also be that @Johannes_B encourage you to use LaTeX \newenvironment for your environment. That will make the closing much easier.
    – StefanH
    Feb 18, 2017 at 10:31
  • 1
    Pascal, i think there are some packages already around to draw timelines. Are you sure you want to add one on top of that?
    – Johannes_B
    Feb 18, 2017 at 11:13

1 Answer 1

1

Structure your code as

document:

\documentclass{article}

\usepackage{mytimeline}

\begin{document}

    \begin{cvtimeline}{2009}{2017}{\textwidth}
        \work{2009}{8}{2013}{8}{Hello}
        \work{2013}{10}{2014}{8}{World}
    \end{cvtimeline}

\end{document}

package mytimeline.sty

\RequirePackage{tikz}

\newenvironment{cvtimeline}[3]{%
    \begin{tikzpicture}%
    % the code that you had in \timeline
}{%
    \end{tikzpicture}%
}%
% Functions
%\def\timeline#1#2#3{%
%   % draw the timeline
%}%

\def\work#1#2#3#4#5{%
   % add an work event and draw
}%
\def\school#1#2#3#4#5{%
   % add an school event and draw
}%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .