Skip to content

Commit

Permalink
Improve relative / ordinal diagram in the docs (#1277)
Browse files Browse the repository at this point in the history
## Checklist

- [x] I have updated the
[docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and
[cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet)
- [x] I have not broken the cheatsheet
- [x] I have tested building the docs

Replace the hand-written diagram of relative / ordinal modifiers with
one generated by LaTeX / tikz.

If it is necessary in the future to change this image, you can reuse and
modify the below latex code to regenerate it.

```
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calligraphy}

% to convert pdf -> png:
% convert -density 300 relative-ordinal.pdf -quality 100 -background white -alpha remove relative_ordinal.png

\begin{document}
\def\spacing{1.4cm}
\newcommand{\ibrace}[4]{
    \draw [decorate, decoration = {brace, amplitude=5pt}] (#2*\spacing, #1*0.8cm + 0.5cm) --  (#3*\spacing, #1*0.8cm + 0.5cm)
    node[above=5pt, pos=0.5, scale=0.8] {\texttt{"#4"}};
}
\newcommand{\bbrace}[4]{
    \draw [decorate, decoration = {brace, amplitude=5pt}] (#2*\spacing, #1*0.8cm + 0.5cm) --  (#3*\spacing, #1*0.8cm + 0.5cm)
    node[above=-20pt, pos=0.5, scale=0.8] {#4};
}
\newcommand{\funk}[3]{
    \draw[fill=black] (#1*\spacing,0) circle (0.1cm) node[below=#2, text width=1cm,align=left,scale=0.7] (F#1)
    {\texttt{"#3"}};
}
\begin{tikzpicture}[ultra thick]

\funk{0}{0pt}{first funk}
\funk{1}{0pt}{second funk}
\funk{2}{0pt}{third previous funk}
\funk{3}{0pt}{second previous funk}
\funk{4}{0pt}{previous funk}
\funk{5}{0pt}{funk}
\funk{6}{0pt}{next funk}
\funk{7}{0pt}{second next funk}
\funk{8}{0pt}{third next funk}
\funk{9}{0pt}{second last funk}
\funk{10}{0pt}{last funk}

\draw[latex-] (F5) -- +(0,-0.8cm) node[below=2pt,scale=0.8] {input target};

\ibrace{0}{6}{8}{next three funks};
\ibrace{0}{2}{4}{previous three funks};
\ibrace{1}{5}{7}{three funks};
\ibrace{2}{3}{5}{three funks backward};
\ibrace{0}{0}{1}{first two funks};
\ibrace{0}{9}{10}{last two funks};
\bbrace{-3}{10}{0}{iteration scope};
\end{tikzpicture}

\end{document}
```

---------

Co-authored-by: Martin Rykfors <martin.rykfors@evolabel.com>
  • Loading branch information
MartinRykfors and Martin Rykfors authored Apr 2, 2023
1 parent 96e06e7 commit d5aa63d
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/user/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ For example, `"take funk blue air"` selects the function containing the token wi

We support several modifiers that allow you to refer to scopes relative to the input target, or relative to the canonical iteration scope of the scope type. For example, the iteration scope of functions is a class, of tokens is a line, of characters is a token, etc.

Here is a diagram of the possible relative / ordinal modifiers:
Here is a diagram of the possible relative / ordinal modifiers using the `funk` scope as an example:

![Relative ordinal diagram](images/relative-ordinal.jpeg)
![Relative ordinal diagram](images/relative_ordinal.png)

([Image source](https://github.com/cursorless-dev/cursorless/blob/main/docs/user/images/relative_ordinal.tex))

And here is a table of the spoken forms:

Expand Down
Binary file removed docs/user/images/relative-ordinal.jpeg
Binary file not shown.
Binary file added docs/user/images/relative_ordinal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions docs/user/images/relative_ordinal.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
\documentclass[varwidth=28cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\usepackage{caption}
\usepackage{subcaption}

% To build:
% pdflatex relative_ordinal.tex
% To auto build on save:
% latexmk -pdf -pvc -halt-on-error relative_ordinal.tex
% To build png:
% convert -density 200 relative_ordinal.pdf -quality 100 -background white -alpha remove relative_ordinal.png

\def\vspacing{1.0cm}
\def\hspacing{0.4cm}
\def\overshoot{0.4cm}
\def\offset{1.2cm}

\newcommand{\abrace}[5][0.5]{
\draw [decorate, decoration = {calligraphic brace, amplitude=5pt, aspect=#1}, very thick]
(#2*\hspacing + \offset, -#3*\vspacing+\overshoot) -- (#2*\hspacing + \offset, -#4*\vspacing-\overshoot)
node[right=5pt, pos=#1] {#5};
}

\newcommand{\funk}[3][black]{
\node[left=1cm,align=right] at (0,-#2*\vspacing) {\texttt{#3}};
\node[align=left] at (0,-#2*\vspacing) [scale=0.8,text=#1,fill=#1!5!white]
{\texttt{def fun():} \\ \texttt{\quad \quad...}};
}

\newcommand{\elide}[1]{
\node[minimum height=0.5cm,scale=1.5] at (0,-#1*\vspacing) {\texttt{...}};
}

\begin{document}
\begin{figure}
% \centering
\begin{subfigure}[t]{.37\linewidth}
\begin{tikzpicture}
\elide{1}
\funk{2}{"third previous funk"}
\funk{3}{"second previous funk"}
\funk{4}{"previous funk"}
\funk[red]{5}{}
\funk{6}{"next funk"}
\funk{7}{"second next funk"}
\funk{8}{"third next funk"}
\elide{9}
\abrace{0}{6}{8}{\texttt{"next three funks"}};
\abrace{0}{2}{4}{\texttt{"previous three funks"}};
\end{tikzpicture}
% \caption{Relative exclusive modifiers}
\end{subfigure}
\begin{subfigure}[t]{.28\linewidth}
\begin{tikzpicture}
\elide{1}
\funk{2}{}
\funk{3}{}
\funk{4}{}
\funk[red]{5}{"funk"}
\funk{6}{}
\funk{7}{}
\funk{8}{}
\elide{9}
\abrace{0}{5}{7}{\texttt{"three funks"}};
\abrace{1}{3}{5}{\texttt{"three funks backward"}};
\end{tikzpicture}
% \caption{Relative inclusive modifiers}
\end{subfigure}
\begin{subfigure}[t]{.3\linewidth}
\begin{tikzpicture}
\funk{1}{"first funk"}
\funk{2}{"second funk"}
\funk{3}{}
\elide{4}
\funk[red]{5}{}
\elide{6}
\funk{7}{}
\funk{8}{"second last funk"}
\funk{9}{"last funk"}
\abrace{0}{7}{9}{\texttt{"last three funks"}};
\abrace{0}{1}{2}{\texttt{"first two funks"}};
\end{tikzpicture}
% \caption{Absolute modifiers}
\end{subfigure}
\\
\begin{subfigure}[t]{\linewidth}
\begin{tikzpicture}
\funk[red]{0}{}
\node[align=left,right=0.8cm] at (0,0) {= function containing input target};
\end{tikzpicture}
\end{subfigure}
\\
\begin{subfigure}[t]{\linewidth}
\begin{tikzpicture}
\funk{0}{}
\node[align=left,right=0.8cm] at (0,0) {= function within iteration scope of input target};
\end{tikzpicture}
\end{subfigure}

\end{figure}
\end{document}

0 comments on commit d5aa63d

Please sign in to comment.