Hi! My name is Eduardo Ochs, I'm the author
of an Emacs package called eev, and the name of
this video is: "Eev and TikZ, or how to
learn TikZ using a REPL"... and this is a
picture of me in and a REPL - you can see that
I'm very happy because I have a REPL
with me.
This video complements what is in this
page here - so I'm going to use lots of
technical terms that are explained in
the web page and I'm not going to
explain them here.
First of all...
I tried to learn TikZ the first time
many years ago, in 2014, and I failed
miserably, many, many times. I've
tried it several times, and
every time I gave up with the
feeling that my brain was too small for
learning TikZ.
And about one month ago I finally found
a way that worked for me for
studying TikZ, and it used links to
the manual - I'm going to show them in
a minute -
I mean links to both the PDF of the
manual and to the source code of the
manual - a REPL that I can run from Emacs,
and a way to extract examples from the manual
Let me show a first example - here.
This link here -
I will have to use a smaller font - this
link here opens my file with notes about
TikZ. You can see that it's
very big... it has about 4000 lines at
this moment, and it's very messy. This
thing here is an index.
Some of the sections are good,
some of the sections are totally crap,
and whatever ... and this link here goes to
the section that I want to
to discuss.
So, this goes to this section here, about
horizontal and vertical lines...
and these first links here point to
the manual. If I open this one - note that
it ends with "page" here - it opens the
page of the manual in the usual sense... in
the sense that it opens a PDF.
It opens a PDF of the manual at this
page, and this is a comment that the
function
find-tikzmanpage ignores, so the
comment is just for humans.
So, if I execute this...
it takes a few seconds because the
the PDF is very big... and it opens the PDF
on page
152 and what I'm going to show is
something related to this example here.
So the manual explains that
sometimes we want to connect two points
via straight lines that are
only horizontal and vertical and for
that we can use this notation, -|,
and this one, |-...
and it gives this example here. So this
is the output of the example and this is
the source code of the example.
Let me go back
If I execute this sexp here...
it will take several seconds to run
because it will have to run a
program called pdftotext to convert
the PDF to text, and the manual is huge...
it's about 1300 pages -
so it takes a while
and then it is going to go to the page
152 of the manual
converted to text - it finds that page by
counting formfeeds - and then it will
search for this string here
in the converted text.
Here -
So this is the the name of the commandn that
was run to generate the converted
version,
and if I do not delete this buffer then
going back to the manual is very quick. So
if I execute this again it goes back to
the manual immediately.
And note that
this corresponds to this section of the
manual here...
and the first obvious way to extract the
source code of these example here is to
simply take this text here,
copy this to my notes and edit this a
bit to delete everything from
this column to the left. And note that
there's an A and a B here these letters
are there because here in the manual in
the example we see an A and a B - here, in
the image.
Until a few weeks ago when I was
extracting examples from the manual I was
always
using these conversion to text here, and
I was editing these things by hand... but
then I realized that
maybe I should take a look at the
source code of the manual, that is a
huge .tex file,
and I could try to see how these
sections and these examples are coded in
the manual... and it turns out that it's
very easy to extract the examples from
the manual.
If I execute this sexp here - note
that the suffix is "file" -
this thing here opens a file with this
name in a certain directory and searches
for the first occurrence of this string
here...
and what we get
is this. Here is the one of the files
of the source code of the manual... here we
have a listing of everything in this
directory... so we have lots of files that
start with pgf-manual-blahblahblah
and we find a subsubsection with this
title here..
and here we have this block,
that starts with \begin{codeexample} and
ends with
\end{codeexample}, and this is exactly the
the source code that I want, so I realized
that in many cases it was much easier to
simply extract
this code here from the source code of
the manual and then try to run that code.
Anyway, let me go back again.
Remember that I said that I
found a way of testing the examples in
the manual using a REPL. This is a demo
of this this REPL... I'm going to explain
it in details very soon - now I just want
to demonstrate how it works.
if I execute these three lines here
then eepitch will create a target
buffer running Lua in the
right half of this frame it will let's
do that now. So now we have this...
And now if I execute this line here
it will make Lua load a certain file,
that is the REPL - no, the tricks with the
REPL that I'm going to explain soon... and
this thing here defines a drawing in TikZ.
And when I run this line here - show() - it
takes a few seconds because it produces
a .tex file, it saves the .tex file to disk...
this sexp here visits the .tex file...
it is just this. So: it has a
header, a footer, and this thing in the
middle.
And it said that, uh...
The class "Show" compiled the .tex file
and everything went well - "Success!!!".
And now I can run this thing here - note
that this is a red star line, so eepitch
interprets everything at the right of
the red star as Lisp, and executes that
as Lisp... and when I do that
it will show the PDF: here.
And the nice thing is that
I can make changes to this drawing. For
example, I can change the scale of the
drawing, and then I can recompile
everything and show the PDF again...
and you can see that the PDF is
always shown here, so it's very easy
to compare one version with another.
And by the way I can even
execute these lines here
in another order - for example,
I can execute this one, and then skip the
second one, and then run the show() and the
(tikz-show)...
So... I've just
changed a parameter in the drawing,
and I produced a new version and I showed
the PDF of the new version.
So this is the way that the REPL works.
There are several variants of this
function here that shows the PDF...
one of the variants is this one -
I can run (tikz-showtex)
here... the scale appears here inside of
the scalebox{...},
so if I change the scale to 1.5, and I
save the .tex again, and I run showtex()
again, this 2 here will change to
something else - it will change to 1.5.
Let's see. Pay attention - here -
ta-da! And now I'm going to show
how to run... no, how people can test this
by installing just four files, and
then I'm going to to show a series of
exercises that I have prepared for
people who want to take this more
seriously and who want to use this tool
to study TikZ by extracting examples
from the manual.
By the way, let me just explain one thing
that is very interesting and very weird
that will appear later, that is this line
here. This function, tiks, is an alias for
the function... find-tikzsearch-links?
Oops, I don't remember! Let me try...
"tiks", with an "s" at the end, is an
alias for find-tikzsearch-links.
And when I run this it produces a
temporary buffer with several sexps
that I can use for locating an
example in the manual... I mean, both in
the PDF of the manual and in the source
code of the manual...
and other related things that we are
going to see soon.
Let me stop this video... and part 2
starts in a few seconds.
Hi! I'm back this is the part 2 of the
video...
In the page about eev and TikZ
the section 4 is called "Trying it".
Let me show it here. Bigger font -
The instructions are here. We are
going to copy this thing to a buffer in
Emacs, but let me just make some comments
before doing that.
We are also going to execute a function
here that will show a certain script,
that contains tests that we will run...
The prerequisites are quite minimal - we
just have to have Emacs, eev, pdf-tools,
that is a package that is in MELPA,
Lua, and a TeX distribution with TikZ.
Let me show how these things work... but
before showing this let me go back to to
here and make some comments.
These red bullets here, they will
behave as red stars even if they
do not show in red.
This is explained here in the main
tutorial. It says that
it is possible to make other
characters play the role of
the red star, and by default the bullet
can play the role of the red star...
And we can run this thing here to make
the bullets appear in red, but I'm not
going to do that now. And the second
comment is that
lines that start with two red stars are
treated as comments, and are skipped.
So, let me copy this thing here to my Emacs -
sorry to a buffer... I'm running an
Emacs in a quite minimal setting,
in a temporary directory... sorry -
this is the home directory that I'm
using, so it's a fake home directory with
just a few things - I have just installed
PDF tools here...
and let me copy this script here. I will
have to use a smaller font...
note that these bullets do not appear in
red, but they are going to behave as red
stars, I promise.
So, f8 here, three times... creates
a target buffer running a shell...
then I'm going to run these things here,
and here we see four "wget"s...
and now I'm going to load this file here.
Note that it corresponds to this file
here.
It defines a few functions. One of these
functions is this one, that just displays
a temporary buffer.
Let me run it now.
It shows this temporary buffer here, with
the script with tests. We have
just run some code that corresponds to this
section here, the section 0 here,
called "Basic installation"... and now we
are going to run this thing here.
These lines start with two red stars,
so they're going to to be treated as
comets, and we are going to see here in
the echo area something that says:
"Comment: blah blah blah blah".
So let's do that now.
And now this line here is going to be
very important. Note that it
has a single red star, so it's not a
comment - it's going to be executed as
lisp and it sets a
an environment variable that says where
Lua should should read its init file
from.
If I remember correctly that
variable is not set now, so if execute
this thing here
Lua will complain that this function,
ee_dofile, is not defined.
So let me run this block again
When I run this line Emacs will
define this environment variable for all
children processes, and I'm going to
restart the Lua interpreter...
Here - and now it's going
to use this
environment variable here, so now this
line will work - it will load this
Lua file here.
We can also execute this with M-e to
take a look at this file.
By the way, it says
"find-angg not configured"...
Let me cheat a bit. Let me run one thing
here without explaining it.
I'm going to explain this in one of the
exercises, I promise!
If I run this thing now,
then it accesses that file by using wget -
I mean it downloads a copy of that file
without saving it to disk...
and I do not have lua-mode installed
in this minimal setting here,
so the colors are a bit boring...
but anyway, we can access this Lua file
here, and now let's run this test. This
test is a bit simpler than the test that
I've shown before.
I'm going to run these four lines here,
and note that this thing has a "tikz"
here...
if I just executed this
then the value of tikzbody would be
just this string here, that
is between these funny delimiters -
between this "[=["
and this "]=]"...
but we had a "tikz" here, and this says
that we have to run the function "tikz"
with this argument, and the function
takes this this argument here and
treats this thing here as something that
has to be expanded... so every time that we
expand this string here, this thing here
between double angle brackets will
be replaced by the result of evaluating
it, and also this thing here,
and also this thing here...
In the beginning this variable is nil,
this variable is also nil,
and
the function that that evaluates these
things between double angle brackets
treats
things that evaluate to nil as empty
strings, so this thing here is going to
become an empty string,
also this one here,
but in this one here something
different is going to happen -
the variable gridsize is nil, but we
have this "or" here, so this thing is nil
and the result of this bigger expression
is going to be this string here. So
the result of
evaluating this part here is going to be
this string here.
I have just
sent this thing without the
"tikz" - let me run this thing again with
the "tikz"...
and now let me run the show() that will
save this thing into a .tex file... I mean,
it will produce a .tex file... it will save
the .tex file, and it will try to compile
the .tex file to generate a PDF.
Ta-daaa: "Success!!!"
Now I can run this thing here -
remember that it starts with a red
star, so Emacs is going to execute to this
thing...
ah, one second... let me
try this again - sorry...
I forgot that I'm in a very minimal
environment, so it
wasn't searching for pdf-tools in the
right place...
Anyway. Note that I have executed
this thing, that is a function... it's a
relatively low level function - it just
splits the frame into two windows, and it
shows a PDF in the window at the right.
We are going to see something much
better in in a few minutes.
Now I'm going to run this lines here
these two lines are sent to the Lua
REPL...
this line also, but this one takes a few
seconds to run, and it shows all
these messages here...
and now I'm going to run this line - the
(find-pdftoolsr-page ...) -
and it shows a changed version in which
gridoptions now...
I mean, this thing here, now when it
is expanded it becomes this string here...
so the grid appears in a lighter color.
And now I'm going to run this block here
and this is going to change the value
of the variable gridsize.
Remember that gridsize appears here...
so when I change this this variable,
gridsize, to this string,
the result of evaluating this expression
here is no longer going to be the thing
at the right of the "or" - I mean this
string here... it's going to be
this other string.
So TikZ is going to use a smaller grid.
Here we have a grid
whose width is six units and whose height
is four units... we are
going to change that to four units and
three units. Let's do that now.
"show()" takes a few seconds to run because
it produces a PDF... and now let's show the
result... ta-daaa: smaller grid!
And here is another part of the demo.
instead of displaying the PDF I'm going
to use the function savetex(),
that just produces .tex, but
does not generate a PDF from it, and this
function here, that displays the .tex file
at the right side.
Let's see. Note that this first line
sets gridoptions and gridsize to nil
and nil again, so we are back in
the initial situation...
savetex() just says
"Saved the .tex file in blah blah blah"...
and now I'm going to run this thing here,
that produces a
a window setting with three windows,
and it shows the .tex file here at the
bottom.
And now I'm going to run this other
block here...
note that I'm changing the gridoptions,
and gridoptions appears here, after the
first \draw, so pay attention to what
happens here in the .tex file
we're going to see that here
appears a thing between square
brackets that says
"[color=gray!20]".
So pay attention... here...
savetex(), and now (tikz-showtex).
And now something similar, but the grid
is going to change to (4,3).
Pay attention here...
So (tikz-showtex) is a low-level
function that we can use to
inspect what happens with .tex file...
And now I'm going to
show the the function that we're going
to use most, that is the function that
instead of showing the .tex file - here -
its shows the PDF file here.
So, same thing. Let's reset gridoptions
and gridsize to the initial state,
show()
and (tikz-show). So this is our initial
drawing -
the grid appears in black.
Now let's change the color of
the grid, and run show() again, and run
(tikz-show)... and now it's going to to show
the changed version of the PDF, in which the
grid appears in light gray.
And now let's change the size of the
grid. The grid is currently 6 units by
4 units, it's going to change to 4
units by 3 units...
that's it - you can see that the rectangle
is smaller.
So, this is the the basic test that
you can run with without installing
anything... I mean, you just need these
prerequisites here...
Emacs, eev, pdf-tools, Lua 5.1, and a TeX
distribution with TikZ...
and by the way this thing puts four
files in this directory, that is hard
coded at the moment... and it creates some
temporary files in /tmp/.
So, now suppose that you are interested
in trying this more. Then my suggestion is:
copy these things here - these lines here -
to your init file.
Some people use init files with other
names, but I prefer to call them by the
the old name which is ~/.emacs...
but this is an abuse of language - I mean,
for some people theirs init file is going
to be ~/init.el, or
~/.emacs.d/ something, whatever...
So let's copy these things here to my
init file...
and now every time that we start Emacs
it is going to set
the init file for Lua to this file here,
as I've shown before, and it's going to
to load
the file that defines this script that
we're using, and blah blah...
um sorry sorry
and if you want to deactivate these
things you just need to comment out
to this region either in this way, or in
this way here...
oops, sorry,
let me do this by hand... sorry, one of my
favorite Keys is not defined.
so, that's it. This thing was commented
out.
But right now I do not want it to
comment it out - I want to use it.
Note that
this thing starts with three comments,
here... I use this a lot in eev - instead
of using customize I use
"setq"s, and "defalias"es, and
"defuns", and whatever else... and there is
a section here that has links that
explain why I prefer to use alternatives
to customize - low-level alternatives -
instead of using customize itself.
And one trick that I always use is
that every time that I put a block of
code in ~/.emacs
I start with the line that says "From:"
that gives me more information about
what these lines do, and where you can
go to understand more about them.
So, if I execute this...
it will open this .el file..
and note that here we have the
definition of find-tikz1-links...
and it is basically just a big
template that displays this thing in a
temporary buffer.
And it also has a link that goes to a
certain anchor in this file...
that anchor points to the place in which
I define the function "tik", without a
"z" at the end...
and it inserts an eepitch block that "runs
tikz1.lua". Let me show how to
use this.
Let me go back to here - this is just a
random scratch buffer... if I run
M-x tik here
it inserts this block... let me show
this again...
it inserts this block, and this is
something that I can modify. I can put
this block in any place, and if I run
this thing here it creates Lua
buffer...
I mean, a target buffer for eepitch
running Lua.
Now this first line loads
tikz1.lua, that defines "tikz"
and "show"...
and here it has a very short demo of a
drawing.
The idea is that this is just a
placeholder that you can replace by
something else...
it's to remind people that you can
put text code inside this thing here.
Now let me run the show()
and the (tikz-show)... and this thing drew
an orange triangle.
I can, for example,
replace this by "red"...
and run this again,
and now my triangle is red.
Let me stop this part of the video here.
In the other part I'm going to
explain these things here...
we have just done the "Not so basic
installation", that lets people explore
TikZ with just a few
settings, and now I'm going to explain
the exercises that
people can use to learn how to extract
examples from the TikZ manual.
So part 3 starts in a few seconds.
Hi! this is the part 3 of
the video,
that is only for the people who are
asking: how can I write things like this,
like this block that we saw in the first
part, myself?
And note that right now, in this minimal
setting in which I'm running this Emacs
here, in a fake home directory, I do not
have a copy of the
TikZ manual, I do not have a
copy of the source of the TikZ manual... so
many of these things are not going to
work. If I execute this thing here it says
that this function is not even defined...
this function is not defined also... this
function is not defined... so it's not even
in a state in which it searches for the
manual and for the source of the menu in
the right places.
What we are going to see is what is in
the
third section here... the section 3 here,
because it has a 0th section.
We just saw the sections 0, 1, and 2,
and we are going to see this one now.
Let me just return and execute this.
Here we are.
I say that these exercises are
explained in this section of the page
about eev and TikZ, but at this moment
this section does does not exist... but it
will exist very soon.
And there is also another similar
function, similar to find-tikz1-links,
that has some spoilers... at this
moment it has very few spoilers but I'm
going to add more spoilers soon.
This section has lots of exercises
and in
this video I'm going to show very
quickly how to do these exercises, and my
recommendation is: watch this
video with subtitles and with the trick
that eev uses to point to positions in
a video,
to follow the instructions in
each of the exercises step by step.
All the exercises are going to be
of the same type which is just
reproduce yourself the steps that I'm
performing in this video... so they do not
require a lot of creativity, I mean, sorry,
they do not require any creativity, they
just require people to familiarize
themselves with some functions that I
use in eev.
And let me make a very important comment
which is that most of the functions that
we are going to see now, they look like
5-minute hacks... my presentation at the
EmacsConf2020 was exactly about that, about
some design choices in eev,
and its title was exactly "On why most of
the best features in
eev look like 5-minute hacks".
But let's go back, and let me show
how to do the exercises.
We just saw how to do this exercise here,
but this exercise (a) here, whose name is
"[tik]"...
it asks us to use M-x tik to
create
an eepitch block that compiles and
displays a drawing whose body is this.
So I'll have to copy this file to my
notes... let me go to my notes - here -
remember that when I type
when I type M-1 M-j this opens
the file with my notes, that is ~/TODO...
so I'm going to put all my
notes about these exercises in this file
here,
which is the file that I recommend
people to use to to put all their messy
things there.
Let me yank these lines here,
let me change the indentation... and if
I run M-x tik it creates a block like
this, but the exercise asks us to change
the body to this other body here.
Now let's run this thing here... I will use
a smaller font -
it created the PDF successfully. Let's
show the PDF. Ta-da - we have a grid with
this size four units in the horizontal
direction, and three units in
the vertical direction, and
this second draw here has drawn a red
triangle here.
So this was the first exercise.
Let me just put some notes here.
Now let me go back to the to the
exercises.
The second exercise is this one.
Let me copy it to my notes.
Actually we have already done that...
it says: copy the lines from the
section 2 to your init
file, restart Emacs, and check that this
thing here works.
Let me try.
Hm, these lines are already there...
I'm not going to restart Emacs because I
I've started Emacs with some command
line options to make it use certain
colors, and it would take me many seconds
to remember how to do that...
Anyway, so let me pretend that we did the
exercise b.
Now let's go to the exercise c,
which is this one...
I have already fixed that but I did
not explain how. The thing is that by
default when we run find-es something
Emacs says that find-es something is
not configured.
In this case... sorry -
let me see what happens here...
so this thing is configured. The
instructions say that we have to
execute this thing here. Let me just
explain how this thing works. If I type
M-x and I run this function here -
find-angg-es-links -
it shows a way to configure find-es and
find-angg... it explains how they
work on my machine and how people
can also use it...
I mean, when I run find-es and find-angg
in my machine they open local files
that have my scripts, my
programs my notes and so on. Other people
can also access my scripts if they
redefine these functions in a certain
way
to make them use wget, and there's a
video here that explains how how this
thing works. So if people
want to understand
what this thing does the recommendation
is: watch these videos here. If I remember
correctly they just need to
watch 30 seconds starting from this
point and another 30 seconds
starting from this point.
So let's let me pretend that this
exercise is done,
and let me go back to the list of
exercises.
Exercise d.
Remember that I said that we don't have
a copy of the of the manual yet...
to download a copy of that manual
in PDF we have to run M-x brep.
If we run this here
it asks for a URL, and then it opens this
temporary buffer here with this script.
If people want to understand what this
thing does they can go to the source
code by running this line here,
and then the comments in the source code
have pointers to the manual,
to the place that explains how these
things work...
and the manual also has some links to
videos, if I remember correctly...
oops, sorry, this this tutorial does not
have links to videos, but it is quite
clear.
Anyway,
to download the local copy we have to
run M-x brep here, and it displays this
temporary buffer and what we have to do
is that we have to execute these
commands here, but it says that...
in my previous test I had already
downloaded a copy of the manual so it's
already there. And we can also use these
lines here to test if the file was
downloaded. It was -
and the
othe part of this exercise says
that we have to produce a pair made of a
code-pdf-page and a code-pdf-text that
makes these links work. This is also
explained in the tutorial. In the page
about the eev and TikZ I'm going to give
links to the sections of the
tutorial that explain everything... but let
me show very quickly how we can do that.
When we ran brep here one of the sexps
that it produced was this one...
now I'm in dired mode, and here I
can type M-h M-e... it creates a
temporary buffer like this,
and what exercise asks is... that
we create links like this that work.
So the "{c}" that we have to put here
is "tikzman".
I have edited this first line here, to
change the value of
of "{c}", and if I run this
line again it will regenerate this
temporary buffer from a template and all
these "{c}"s are going to be replaced by
this new value here - "tikzman".
And now we have this block of
links that point to a certain PDF file...
and what the exercise asks is that we
produce these code-pdf-page and this
code-pdf-text if I execute them...
let me execute them. The first one defines
this function here, find-tikzmanpage,
the second one defines this function here...
remember that if you need more
information about what they do you can
just add a "find-" here in the beginning
and then
execute this new sexp and then it will
have some explanations, a link to the
tutorials, and so on...
but now they have defined these things
and this sexps should work. This one
should open the manual in
PDF - this is the first page of the manual
in PDF -
and this sexp here is going to take
many seconds because the manual is huge...
and it's going to open the the manual
converted to text.
So a bit of patience please...
a bit more please...
oh no, it takes ages!...
Here we are.
this thing worked correctly it ran
pdftotext to convert the manual to text,
and at some point we're going to use
this thing to
point to titles of sections, sometimes
we're going to use this to copy and
paste examples, and so on...
so the answer to this exercise is these
two "code-pdf-*"s -
these two "code-*" lines. And these two
lines here are tests.
Let me go back to the exercises. Now
I'm going to show how to do the
exercise e.
The exercise e says that we have to
start from this URL here, that points to
a git repository, and
we have to use this to download the
source code of the manual... and we
have to define these three...
we have to make these things
work using `code-c-d's.
And here people will have to consult the
spoilers because it's not clear what
this directory means... I mean, to what
directory this thing has to
point, and to what directory this thing has
to point, whatever...
Anyway. I can type `M-h g',
and it runs a function called
find-git-links...
and now I can run this script here
and it clones the git...
oh no -
It used the wrong directory.
Let me fix that. Sorry.
So now the cd worked...
it's downloading - I mean, it's cloning the
git repository...
and if I want I can inspect the git
repository using these links here -
but I do not want to do that now.
What I want to do is that I want to
create something like this,
but with a different name... I want to use
something different instead of "pgf" here.
So let me copy these two lines
to my notes...
what I'm going to do here is that I'm
going to replace "pgf" by "tikzgit"...
TikZ is actually PGF/TikZ, but
the name PGF is not used so much, so I
preferred to use the name "TikZ" almost
everywhere.
So this thing here defined
this function - code-tikzfile -
and several other functions...
remember that you can inspect
what this code-c-d does
running a sexp like this...
it defines this variable, ee-tikzgitdir,
and lots of functions with "tikzgit" in
their names... and if people need more
information about how this works
they can use these things here to go
to the tutorial.
So if I run this then I define
find-tikzgitfile, find-tikzgitgrep, and
other links like this, and this one opens
the source code of the manual...
and I also need some variants
of this... let me open the spoilers.
Here. What I really want is these three
`code-c-d's here...
and this one is obvious - it goes to the
copy of the git repository... this
one goes to the
directory where the source code of git
itself is - I mean, when you use
\usepackage{tikz} in your .tex file
it load files that were
originally here, but that were then copied
to the texlive distribution... sorry, to
tex texlive directories.
And this one is going to be very useful
and very used...
that is the source code of the manual
of TikZ.
Here we have
all the sections, and
chapters, and subsections, and whatever,
of the manual
in .tex files. We're going to use that
soon.
So, now...
well, the exercise e said that we had
to produce these three `code-c-d's
that make these sexps work...
and now they do work. This
one opens the copy of
the git repository, this one goes to
the source code of TikZ itself and
this one opens the source code of the
manual.
So now let me go back to the
exercises again...
we have just done this exercise here...
Let me copy these two exercises to my
notes at the same time...
This exercise here asks people to
put more things in their init file.
It asks people to copy these
things to their init file, and it
recommends using the spoilers.
And the idea is that we are going to
copy this thing here to the init file...
and remember that if we type M-5 M-5 M-j
then we open the init file.
So let me copy this to the init file...
and note that
it has a "From:" line here, and the line
with the "From:" can be used to...
I mean, I forget things all the time, and
so I use these things to go back to the
places where the functions were defined,
where I found the instructions, and so on.
If execute this thing I go to the
temporary buffer with spoilers, and I see
this block here... that is where
this thing here came from.
Now the exercise g, called "[page]"...
it asks us to create links to a certain
page in the manual.
If I execute this thing it goes to the
conversion of the manual to text,
and the exercise says that we have to
produce a pair like this,
that points to that page...
and what we have to do is that we have
to go here, then we have to mark this
string and copy it to the key ring, and
then we have to type `M-h M-p'...
and then this is the pair
that we want.
This first link here opens the PDF of
the manual at that page...
those coordinates appear here, in
the middle of the
the instructions for drawing this
envelope here...
and now this thing here has a number
here saying to this function that it has
to count the form feeds to go to page
30 in the conversion, and then it has to
search for this string in the
manual converted to text. If I execute
this
it goes exactly to this page
but it also has this indication that we
have we are in page 30.
Next exercise: "h) [src]".
In this exercise we have to
to learn how to create a link to the
source code of the manual...
and we are also going to have to learn
how to use this - `tiks'. This is a 5-minute
hack, in the sense that I've mentioned
earlier and that is explained... I mean, the
design decisions behind these
5-minute hacks were explained
in my talk at the EmacsConf 2020.
If we execute this it creates a
temporary buffer with lots of hyperlinks,
and the idea is that we have to understand
what these hyperlinks do...
and we have to produce a hyperlink like this,
that points to a certain section of the
source code of the manual.
note that we don't have links like that
here... but we will have to use the grep
here to grep
in the directory that has this shorthand...
it found one occurrence of this
string, in this file here... so what I have
to do is that I have to visit this file...
if I type enter here it will go
to the line 271...
then I'll have to copy this thing to the
kill ring... and now the best way to create
a link to this string is to use...
I mean, the traditional way is by typing
`M-h M-h', here and then editing...
duplicating this line, editing this line
to add this string here, and so on... but
one of the things that I'm going to
present in the EmacsConf
is a very fast way to create
links like this.
So if this thing here is in the region -
in this case the region is not active,
but it is there -
and I type `M-x klfs'
this kills a link to a file and
a string in that file...
so if run this -
Gaaah! God! =(
Oh no, this is not loaded by default...
Let's see if I...
I'll have to to fix this later,
but let me
fix this by hand, sorry...
Let me see if this works now...
Ah, yeah! Sorry!
Let me do some mysterious things right
now...
I have use these aliases here.
Let me put these aliases in my...
Let me copy these aliases to the init file
and execute them...
so now this thing should work...
if I
mark the region here and I type `M-x klfs'
this should put in the kill ring a
link to this file and to this string in
this file.
Oops - let me run this again...
The message in the echo area says that
this has killed this sexp here...
and let me go back to my notes...
this is the link that the
exercise asks for.
If I execute this link I go to this file
and the source of the manual, and it
searches for the first occurrence of
this string there.
Next exercise...
"i) [tiks]".
Let me go back to my notes...
it says: start from this
hyperlink and make sure you know how to
use all the hyperlinks in the temporary
buffer that this function here, `tiks', has
generated.
This first line here just regenerates
the buffer in the sense that if I make a
big mess here I can just execute this
individual reconstruct the buffer in the
original way. This second line uses
a synonym for `tiks'...
this third line here goes to
the definition of this function -
it is here, and after the definition we
have a defalias,
so the two functions are equivalent.
This thing here is going to use wget to
access one of the files in my home site.
It has some notes about TikZ, and here
is an index that I have prepared
for the chapters of the manual - but this
index supposes that we are using an
older version - long story -
so the pagination is not correct...
for example, probably this thing
here is not going to point...
no, this one works but
let me see what happens here...
this one is four or five pages behind.
The right value here should be
something like this...
Almost!
Anyway, this is an index for
the chapters in the TikZ manual,
that is not going to work for you
because...
well, in the other exercises
I recommended to download the current
version of the manual...
and note that
this thing was downloaded by wget, so
it's in a temporary buffer...
in this case this
link is not going to work very
well because
this thing is not the name of a
chapter, it is the name of a subsection...
but whatever... this link here
is more like a button than like a link -
it puts this string in the kill ring.
We are going to see soon how to use that.
This thing here opens the the manual in PDF
in its page 3, where it has the table
of contents...
this one here opens the page 3 using
the conversion to text and now we can
use this thing here that I
have just pushed into the the top of the
kill ring to search for a certain string
if I go here and I type C-s
I enter the mode that performs
interactive search... if I type M-y here
it puts
the top of the kill ring here and I can
use that to find this section
in the manual.
And now I can search for other
occurrences here... because probably
I do not know a link to this page.
No, sorry, let me change the exercise
a bit. I will use this string here
to create a link to the index...
so this thing here is section
14.2.2 that appears
here, in very small letters...
and after doing that I can also
search for this other string here...
and use M-h M-p again to produce
a pair of links that go to the
real section in the manual.
So this goes to this section - here -
and this goes to this section converted
to text.
Let's go back. I was explaining
the lines in this temporary buffer here...
and this one was a bit mysterious, but
I have just explained how to use it.
These lines here...
in theory they go
to the index of the the manual, at the
very end...
and remember that you can
execute this to go to the source code
of that function,
and we can use that to change that to
the right numbers...
this is a bit advanced, but let me
explain it anyway.
The index is a few pages ahead of that...
that number. Let me see how many...
oh, no! Many pages. So, in this version
of the manual the index
starts at the page 1271
instead of 1235,
and I can go to the source code of
this function, and I can change this to
1271...
and then I can redefine this function,
and then I can use this to regenerate
this buffer, and now it has now it has
the right links to the index.
So this first link here goes to the
beginning of the index, but it
ignores this string...
and this other link here goes to the
beginning of the index and then it
searches for the string. I guess that
that is not going to work -
it says "Search failed", but whatever -
for other strings this would
work very well. For example,
if I wanted this...
then I could just use this thing here to
create
a link to where a certain string appears
in the index.
Well, as I've said in the beginning
this is a 5-minute hack with many
small hacks inside... and I've just
explained how we can fix the index, and
how we can create
links to an entry in the index.
These three lines are easier. We just saw
what they do. This goes to the
to the copy of the git repository,
this one goes to the
to the source of the manual, and this
goes to the source code of TikZ and
PGF themselves.
We can use this
three grep links here to search
the whole copy of the git
repository, or to... sorry, to search just
the source of the manual, or to search just
the source of TikZ and PGF.
And note that
I've used the an uppercase R here to to
specify that this grep has to be
recursive.
This one finds one occurrence,
this one also...
and this does not appears in the
source code of TikZ, I mean...
when people run \usepackage{tikz} then
this loads lots of packages and this
string does not
does not appear among the these packages -
these .tex files and the style files
that are loaded by \usepackage{tikz}.
And we can also use these URLs here
to go to the... oops -
I do not want to do that now, sorry... I'm
in the fake home directory... but we can
use this to to open the git repository
using a browser
So these are the explanations
for all the lines that appear in the
"make sure that you know how to use all
the hyperlinks"... there are many, and
some are quite technical. I have
just explained all of them.
So this was exercise (i).
Let's go to exercise (j).
Exercise (j) says
that we should start by this
hyperlink here, and
we have to use this to produce links to
a section of the manual. So this is
similar to what I did here,
but here I produced links to a section
called "Horizontal and Vertical Lines",
that was actually a subsubsection,
or a subsection, whatever...
And let me show how how we can do this.
My favorite way of doing this is by
using this to put the string
in the kill ring, then I go to the
table of contents, then I
search for that string...
it's in this chapter here...
then I go to that chapter with
C-s and M-y
and then - oops, sorry...
and then I will create a link to
to this string here in that page,
with the right number of spaces here...
so let me put that in the kill ring,
and M-h M-p...
and this is a pair of links that point
to this section in the manual.
Here we are...
and this one
opens that section in the manual
converted to text
so this was exercise (j).
The next exercise -
exercise (k) -
is similar to that one, but it asks us to
create... uh, no, no, sorry -
this one is different!
This one says that we
have to start from this hyperlink and
then we have to find the source code
for a certain example.
We have to use this link here
to find that section in the source
of the manual
let me first create a link
to this string in this file... let me copy
it to my notes...
I have just just created something that
is useful to me, but that is not exactly
what the exercise asks for, that is
a link to a certain section
of the manual in the source code of the
manual. And now that I have this link
I'm going to search for
a certain \codeexample here - it is here -
now I have to run `M-x tik' here...
and then I will
change the body of this example
by the body of this \codeexample in the
manual - this one here.
Now let's test this.
It worked! Ta-da =)
We are almost at the end...
let me see what is the next exercise...
We were at exercise (k).
Now we have to do exercise (l).
This one is similar to the to the
previous one, but instead of using tikzbody
we have to put this
string in another variable.
This links here searches for this
string in the source code of the manual...
I want this code example here.
and now I create a block like this one,
but this block here is going to to have a
an empty tikzbody,
so it's going to produce an empty figure...
and I'm going to copy this thing here
to the variable "hello".
The name is a bit silly, but the thing is
that in some of my early tests I just
did... one second...
I just did this with an empty tikzbody,
and when I run this block here
it just shows a "HELLO". That is...
I mean, it runs this this code here
outside the tikz block.
But...
the hint says to put this thing here in the
variable "hello".
If we want more information about
what does this does
we can go to the
to the source code in Lua...
sorry for the lack of colors, I forgot to
install lua-mode here...
but... the texbody is here, and before...
this block here defines a
tikzpicture inside the \scalebox,
and just before that I have a hello.
Anyway, the exercise asks for this,
and if you if you run this thing here
it runs these very low-level
commands here...
\pgfkeys is the low level way to
define styles in TikZ,
to make a very long story short.
So: the output of this is the result of
these two things here, as text.
This is super technical I'm not going to
explain that now...
But let me go to the
exercises again. We have just run the
exercise (l)...
now we have the exercises (m) and (n).
(m) is also quite technical... people are
going to need something like this
if they need to run advanced examples
from the tutorial.
Let's first search for
"magnetic field" in the manual.
If we simply search for this, the
first occurrence of "magnetic field" in
the manual...
hm, it's probably in the page
565 or 566, so let me start by creating
links to this page of the manual.
Here we are. Let me copy them to my notes...
the string "magnetic field" appears here
in this figure...
and if the string appears here it's
because it also appears in the
source code, so let's search for it in
the source code.
Here it is: "magnetic field".
The exercise asks us to use this thing
here to find the first occurrence of
magnetic field in the source code of the
manual,
so we have to use this grep here.
Now let me create...
let me use this link here...
and now the exercise tells us to
create a TikZ block that runs this
example here.
But this example is not just a tikzpicture,
it also has some extra options -
here, just after the \begin{codeexample}.
If we just create a tikz block
that runs this thing here...
let me put that in the
in the tikzbody...
and let me try to execute this
thing here...
the show...
instead of saying "Success!!!" it says
that we had an error, and it does not
know how to explain what is that error.
So now we can run this thing here to
show the log of pdflatex...
sorry, of lualatex...
and the log says this:
is that it doesn't know how to run
"canvas (something)" - here.
it doesn't know how to run this.
And the trick is that we need to set
this "preamble=" somehow,
and the exercise says what we have to do...
it says that we have to load this
library here, and if we run this new
version of the eepitch block
now we have a "Success!!!" here, so
it has created a PDF correctly.
The log says the details,
but it's not very important now.
And ta-da! We were able to extract
that example from the manual and to
create an eepitch block that
runs that example.
so this was exercise (m).
And now we have a VERY technical
exercise. I mean,
most people who use latex are going to
find it completely mysterious, but
let me show it anyway.
The last exercise
says that
we have to execute the test blocks in
these files
this one here goes to the copy
of this file in my site - it uses wget...
and this one goes to the local copy.
Let's use this one.
Let me spend a few seconds more to to
load lua-mode, because this thing is
going to be much more easier to
understand if I...
oh no -
I'll have to cheat a bit. One second.
Hm,
you are not expected to understand this...
let me run this thing again...
Now this is going to load all packages from
MELPA, and it's going to display them...
it takes a long time...
wow, it's taking much longer than I
expected...
whoops...
let me install this thing...
it's installed.
Hm,
I forgot to to copy the last exercise to
to my TODO file - to my notes...
now I've copied it.
Now if I open the local copy of this
Lua file here it's probably going to
be able to fontify everything
correctly...
no, it didn't!
Anyway, sorry...
sorry for not having installed
lua-mode before. anyway now we have the
colors, and we can see clearly
that this thing is a big comment and
this thing is a test block,
and we can run this test block here to
understand how these
functions work... and this is the super
technical thing that I want to explain.
This line here
says that
we will
prepare a .tex file that will not
generate a PDF, because it will stop
before... it will stop in the middle of the
execution when lualatex is trying to
compile it, and it will stop because it
will run a REPL, and not the default
TeX REPL... it will run a
REPL in Lua
that is defined here... here we have
an explanation...
it says that when we run this
then
texbody will include this block of
code here...
and this block of code will
load a certain Lua file into lualatex,
and then it will run this \repl,
that is defined in a very mysterious
way.
Anyway let's run that in practice. If
we execute this,
then...
I have just saved the the .tex file, I
have not asked
my Lua files to to run latex on
it...
and now I'm going to run lualatex
on it inside a shell - here...
inside another REPL that is running a
shell.
if I run this then it
starts the compilation and then it gives
this prompt here, and this prompt here is
a Lua prompt.
And
now I'm going to run these things here...
for example, printmeaning("newpage") will
run a certainly mysterious thing, and it
will say that the definition of
\newpage is this thing here.
So \newpage is a
TeX macro that is defined in this way,
and this printmeaning(...) here will do
something similar, but with it will
use a very low level trick to discover
what is the current meaning of
"rounded corners" for TikZ...
so "rounded corners" has this definition
here... and
this thing is the same thing but in
a shorter version, and this thing is the
thing in an even shorter
version, and this one
shows the definition of "right", that
we use sometimes to specify
how labels have to be placed.
So this is a way to inspect definitions
from inside the Lua REPL. It's something
super tricky and
at the end of this this page here...
I'm not sure if if the links are already
there, but I'm going to explain...
uh, to give some links about how these
things work.
Hm, no I don't have the links right now...
I had to ask some questions at
StackExchange and StackOverflow to
understand how to do these things,
and...
the whole story is that I wanted to
do something much more complex...
I wanted to be able to expand a
\pgfkeys{...} from this REPL, and then I
asked the question, and then people
explained to me why that was impossible...
so what we have
here is something much more humble...
instead of of expanding
definitions using PGF
this thing here simply
shows what is the current definition
without any expansions.
This is a long story, it's super technical,
I'm going to explain more about this in
the page at some point, but it's...
I mean, here -
no I mean here - but it's not ready yet.
And...
so, that's it - this finishes all
the exercises. Let me
stop the video now,
and then I'm going to put more material
in the page, and I'm going to add
subtitles to this video, so that people
can use the subtitles to
see how to perform the
exercises...
So, that's it. Bye!!! =)