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

cfr
  • 198,882
Bernhard
  • 1,248

1 Answers1

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

cfr
  • 198,882
  • 1
    Basically the same method as here. I really ought to finish the package version of this. – Alan Munn Nov 08 '23 at 01: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 08 '23 at 01: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 08 '23 at 01: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 08 '23 at 02:46
  • @AlanMunn So shade over the top of the text? – cfr Nov 08 '23 at 02:48
  • Yes, I don't know why that doesn't work in the proof example, but it does in the algorithm example. – Alan Munn Nov 08 '23 at 03:21
  • @AlanMunn How does pgf associate saved positions with current references on the second run? If I look at the aux file, I have no idea what the relationship between the saved locations and the defined \tikzmks are. Does it just rely on ordering? If I only include the fitch proof, the numbers start from 2. If I include the algorithm, they start from 1. – cfr Nov 08 '23 at 03:21
  • I have no idea. ;) – Alan Munn Nov 08 '23 at 03:26