2

I'm using the fitch package (the one written by Prof. Selinger and is now maintained, I believe, by Richard Zach) for pedagogical purposes -- as I suspect many people do.

It would be helpful to be able to highlight parts of proofs with shading. I'm afraid I don't really know how to do that. I know how to put a whole proofs inside a shaded environment, e.g., with the mdframed package.

I've included a MWE for a simple fitch-proof, as well as an image of what I'd like to be able to shade with a box drawn in by hand.

\documentclass{article}

\usepackage{fitch}
\begin{document}

\begin{displaymath}
\begin{nd}
  \hypo {1} {P \lor Q} \by{}{}%
  \hypo {2} {P \rightarrow R} \by{}{}%
  \hypo {3} {Q \rightarrow R} \by{}{}%
  \open%
  \hypo {4} {P} \by{}{}%
  \have {5} {R} \by{}{}%
  \close%
  \open%
  \hypo {6} {Q} \by{}{}%
  \have {7} {R} \by{}{}%
  \close%
  \have {8} {R} \by{}{}%
\end{nd}
\end{displaymath}

\end{document}

enter image description here

1
  • Please check code compiles before posting. You cannot use standalone here.
    – cfr
    Nov 8, 2023 at 0:10

1 Answer 1

1

You can pretty easily highlight the relevant part of the proof using a box by placing tikzmarks appropriately and drawing a tikzpicture afterwards.

For example,

\documentclass{article}
% ateb: https://tex.stackexchange.com/a/700683/  i gwestiwn Bernhard: https://tex.stackexchange.com/q/700671/    
\usepackage{fitch}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usetikzlibrary{fit}
\usetikzlibrary{calc}
\begin{document}

\begin{displaymath}
  \begin{nd}
    \hypo {1} {P \lor Q} \by{}{}%
    \hypo {2} {P \rightarrow R} \by{}{}%
    \hypo {3} {Q\tikzmark{a} \rightarrow R} \by{}{}%
    \open 
    \hypo {4} {\tikzmarknode{b}{P}} \by{}{}
    \have {5} {\tikzmarknode{c}{R}} \by{\tikzmarknode{d}{\strut}}{}
    \close
    \open
    \hypo {6} {Q} \by{}{}%
    \have {7} {R} \by{}{}%
    \close
    \have {8} {R} \by{}{}%
  \end{nd}
\end{displaymath}
\begin{tikzpicture}[remember picture,overlay]
  \node [fit=({pic cs:a} |- b) (b) (c) ($(d.south)!.75!(c |- d.south)$),draw=red] {};
\end{tikzpicture}

\end{document}

highlight part of proof using red box

If you actually want to shade that part of the proof, as opposed to drawing around it, things are considerably trickier. Until the proof is constructed, you don't know where to shade; after it is constructed, you can't easily shade beneath it.

One approach would be to put the proof inside a tikzpicture. Then we can use the backgrounds library to shade the relevant sub-proof after the proof is constructed. For example,

\documentclass{article}
% ateb: https://tex.stackexchange.com/a/700683/  i gwestiwn Bernhard: https://tex.stackexchange.com/q/700671/
\usepackage{fitch}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usetikzlibrary{fit}
\usetikzlibrary{calc}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[remember picture]
  \node [align=center] {%
    $\begin{nd}
      \hypo {1} {P \lor Q} \by{}{}%
      \hypo {2} {P \rightarrow R} \by{}{}%
      \hypo {3} {Q\tikzmark{e} \rightarrow R} \by{}{}%
      \open 
      \hypo {4} {\subnode{f}{P}} \by{}{}
      \have {5} {\subnode{g}{R}} \by{\subnode{h}{\strut}}{}
      \close
      \open
      \hypo {6} {Q} \by{}{}%
      \have {7} {R} \by{}{}%
      \close
      \have {8} {R} \by{}{}%
    \end{nd}$
  };
  \scoped[on background layer]
  {
    \node [fit=({pic cs:e} |- f) (f) (g) ($(h.south)!.75!(g |- h.south)$),fill=cyan!25] {};
  }
\end{tikzpicture}
\end{document}

shaded subproof

8
  • 1
    Basically the same method as here. I really ought to finish the package version of this.
    – Alan Munn
    Nov 8, 2023 at 1:14
  • @AlanMunn Thanks. I'd not seen that (as far as I remember). Interesting. I guess you mean my method is akin to your more complicated version? But I'm not sure whether the simpler one would work in this case. tikzmark works in maths and text modes, which makes the markup a bit simpler. And your simpler case wouldn't work for shading, would it? Which was what the OP asked for.
    – cfr
    Nov 8, 2023 at 1:27
  • @AlanMunn Actually, your version almost works for the boxing case. I guess the maths stuff is OK since it's not ending up in your nodes. Could it be used to box the sub-proof? That would definitely be interesting. I don't see a way to do shading that way, though?
    – cfr
    Nov 8, 2023 at 1:40
  • Yes the math isn't the issue. I don't know what the sub-proof is, so I can't answer that question. :) I was assuming shading would work just by adding fill to the node (like this version) but somehow that doesn't work in this example.
    – Alan Munn
    Nov 8, 2023 at 2:46
  • @AlanMunn So shade over the top of the text?
    – cfr
    Nov 8, 2023 at 2:48

You must log in to answer this question.

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