2

I am trying to output a number relative to the current step of my proof instead of being hard coded. I'll try and explain what I mean with this proof:

\documentclass[11pt]{article}
    \usepackage[a4paper,total={6in,8in},textwidth=496pt]{geometry}  
    \usepackage{amsmath}
    \usepackage{amstext}
    \usepackage{flagderiv}
    \usepackage{calc}
    \usepackage[nomessages]{fp}

\begin{document}

\begin{flagderiv} \step{}{P}{} \step{}{P\implies Q}{} \conclude{}{Q}{1&2} \end{flagderiv}

\end{document}

code above

Instead of having to write 1\&2 in the conclusion section I would like to find some way of using the step counter to get just say the line above this one.

I know that flagderiv has a \thestepcounter variable but that gives me the number in this format: (n). I was also thinking of using fp (which I found in this answer) to do the maths in some way like this: \FPeval{\result}{clip(\thestepcounter-1)}. I have yet to find a variation of this that works though.

This feels possible, but I'm quite new to latex and manipulating variables in this way is beyond me. After reading parts of the Implementation section in this pdf I think \thefd@stepcount might be the variable I'm looking for, but it seems to be internal and I don't know how to access it.

Any help is much appreciated. Thank you in advance!

Non808
  • 35

2 Answers2

3

The first argument to \step (which you are leaving empty) is a label, which can be referenced by standard methods.

\documentclass[11pt]{article}

\usepackage{flagderiv} \usepackage{amsmath}

\begin{document}

\begin{flagderiv} \step{foo}{P}{} \step{bar}{P\implies Q}{} \conclude{}{Q}{\ref{foo} & \ref{bar}} \end{flagderiv}

\end{document}

enter image description here

campa
  • 31,130
  • Excellent thank you! That is definitely the easiest way of doing it and thank you for explaining the first argument of the step command! – Non808 Nov 25 '20 at 10:04
  • I'm getting inconsistent red boxes around some of the \refs they are like hyperref boxes (but red) and yet the correct number is inside them. – Non808 Nov 26 '20 at 14:54
  • @Non With this code? – campa Nov 26 '20 at 17:41
  • Yes it was really weird. The output would be exactly right but there would be hyperref like red box around it. It was inconsistent as well on one document it would work another not. Waiiiit – Non808 Nov 27 '20 at 15:11
2

Here a new command \relativeRef{<num>} is provided (you can surely use a shorter macro name). For example in line 3, \relativeRef{2} will give 1 (3 minus 2). Note that the underneath counter is named fd@stepcount.

\documentclass{article}
\usepackage{amsmath}
\usepackage{flagderiv}

\makeatletter \newcommand{\relativeRef}[1]{% \the\numexpr\c@fd@stepcount-#1\relax } \makeatother

\begin{document} \begin{flagderiv} \step{}{P}{} \step{}{P\implies Q}{} \conclude{}{Q}{\relativeRef{2} &amp; \relativeRef{1}} \end{flagderiv} \end{document}

enter image description here

muzimuzhi Z
  • 26,474
  • That is also a good way of doing it thank you! Good to know how to access the variables from the package! – Non808 Nov 25 '20 at 10:05
  • @Non What does the word "variables" mean? I learnt the name of counter, which is fd@stepcount, from source code flagderiv.sty, by searching keywords like \newcounter and/or \steprefcounter. – muzimuzhi Z Nov 25 '20 at 13:18
  • I just mean the counter itself being a variable. In the flagderiv pdf it says This exposes the internal \thefd@stepcount command. which I assumed to mean that there must be internal variables as well. – Non808 Nov 26 '20 at 12:15
  • @Non The internal control sequence representing that counter is \c@fd@stepcount, in the form of \c@<counter name>. \c@fd@stepcount is an integer register. – muzimuzhi Z Nov 26 '20 at 14:21
  • Aaah good to know thank you! – Non808 Nov 26 '20 at 14:49