Conversion pages (Mac) from Inline LaTex document using Keyboard Maestro macro

Trying it in another way. (I think writing a new article would be a waste of space, so I reply to my original article.)

I wrote the macro in the following way.

  1. Search for $ by "find".
  2. Move the cursor one space to the left of $.
  3. The cursor keeps moving to the right while holding the shift button
  4. Move until a new $ mark appears, and the cursor stops as soon as $ passes

This way, you can safely copy only the equation from $Equation$ and paste it into the equation window on the pages. But in this case, it is difficult for me to complete step 4). The cursor does not stop and continues to move to the end of the document. Is there any action that can make 4) possible?

Thank you.

That's correct.

You posted

  1. Copy only x=4, from $x=4,$ and enter it into the equation input window (then click the Insert button)
  2. Copy only y? from $y?$ and enter it into the equation input window (then click the Insert button)

and I understood you to mean you were first doing the x expression and then you were doing the y one, in two separate steps, not as one step.

So, what you want is to be able to have something like

"In the matrix equation above, if $x=4,$ what is the value of $y?$"

in the clipboard and paste that into the equation facility in Pages, but without the $ signs - is that correct?

Yes, that's right. I cannot but admit that the description in my original article was insufficient.

$math$text$math$text

In this way, I want all the $ signs to disappear and the math to be rendered well.

But it's not, is it, for what I suggested (namely paste the whole thing without dollar signs into the equation editor in Pages) will not render properly.

What you actually need for the text to be pasted into Pages unchanged, but the maths expressions to be entered via the equation editor.

I'm just trying to clarify what it is you're trying to achieve. To take your example

$math1$text1$math2$text2

Is this what you want to happen:

  1. Enter math1 via the equation editor
  2. Paste the text1 into Pages
  3. Enter math2 via the equation editor
  4. Paste the text2 into Pages

To be absolutely certain, it would be better if you posted actual examples of

(a) the text that you start with, and
(b) what it looks like in Pages after it's been properly entered

I you can supply that then so much the better!

First of all, thank you. I will explain through the picture.

The picture below is the math problem given to me at first

The output after the macro should look like this:

LaTex source is as follows:

$\left[\begin{matrix} 2 & 4 & 1 \ 3 & x & 7\end{matrix}\right]+\left[\begin{matrix} -2 & 5 & 4 \ 1 & 2 y & 3\end{matrix}\right]=\left[\begin{matrix} 0 & 9 & 5 \ 4 & 6 & 10\end{matrix}\right]$

In the matrix equation above, if $x=4,$ what is the value of $y ?$

(A) $-6$
(B) $-2$
(C) $1$
(D) $2$
(E) $6$

In a nutshell, it may sound a bit abstract, but I want the "$math$" to disappear sequentially, turning it all into the rendered "math".

Tangent to your question but clarifying the method in LaTeX ... punctuation marks (comma and question mark) should be rendered outside of the equation limits not inside them. So $x = 4$, not $x= 4,$.


JJW

Oh, thank you!!~

I’ve now looked at your example and I have figured out a way to achieve what you want.

Well - that’s the good news!

The bad news is that it is so complicated there must be different, simpler ways of solving the same problem. It’s just that I currently don’t have enough spare time and brain power to go further.

So, I’m hoping some kind (and canny) soul will step in and have a shot at helping you and we can both learn a bit more.

I might hazard a guess that the KM conversion will need a loop that pulls apart a sequences of (regular text + LaTeX) + (regular text + LaTeX) + ... The command will paste the regular text into Pages. At each LaTeX, the command will have to open the equation editor in Pages, enter the text, and exit the editor (invoking it). Repeat this until the end of the text buffer.

When this is to be done on more than one set of inputs, I have to wonder why not just use a LaTeX compiler directly?

--
JJW

That's a bird's-eye view of what's needed: I've already worked out how to identify where each LaTeX element is by locating the dollar signs (and therefore where each text element is) and written a macro to do that but the iterating loop that then extracts these elements turns out to be very fiddly. But that's my take on it and I was wondering if there might be another, simpler approach that someone can suggest. It seems to me that while KM can process text sequentially, it's not necessarily something that KM makes easy to do!

I'm not really familiar with LaTeX so your suggestion to use a LaTeX compiler sounds to me like that could be the more straightforward approach.

This is a discussion worth a thread on its own. Suffice to say that, the (highly) recommended on-line compilers are OverLeaf or ShareLaTeX, and the macOS local installation is (so easy, a caveman can do it) found at MacTex.

I think perhaps that the OP is trying to get out of investing time to learn LaTeX and instead wants a parsing tool to be able to copy+paste someone else's LaTeX work to his favorite WYSIWG text editor (Pages).

But, that is also a subject for its own thread (not here).

--
JJW

1 Like

Thank you for providing a new perspective.

I have also considered using LaTex compilers like "Lyx" or "Overleaf" before, but I have come to the conclusion that these compilers are more suitable for writing "Professional" math or scientific papers.

The document I wanted to create had to be in a more free form with pictures, text, and equations, so I considered "Pages".

Perhaps even with a direct LaTex compiler, various images, texts, and formulas can be freely implemented like a textbook that elementary school children see, so I will study more.

Thank you sincerely. :slight_smile:

I am really grateful that I can learn some new features through the macros you provided at the beginning.

The way macros work sequentially seems to be harder than I thought before.

Even if it is not resolved soon, I think it is productive enough to ponder these problems.

If you have a good idea or solution, please feel free to tell us. I will post more. Thank you.

1 Like

If I get more time I will be sure to add to this discussion with a view to being more helpful :slightly_smiling_face:

OK - I'm not one to let go easily so I took a little time out to tackle the problem and I have, I hope, a solution for you!

Here is a screen shot of Pages showing the input to my macro and the resulting output from it. I think it looks passable.


To use the macro, you must copy the raw source text into the clipboard and then trigger the macro; I've set it to trigger on [hyper]-; but of course you can set it to whatever you like.

The macro will then activate Pages, to make sure it's at the front and then do it's stuff.

Here is a copy of the macro: Pages with LaTeX.kmmacros (33.5 KB)

This is what the macro looks like, but I am not going to explain it as (a) it's complicated and (b) I am pressed for time!

I hope this gives you many ideas should you wish to modify and/or improve it!

EDIT: I was just playing around with this and discovered an omission such that if there was plain text after the last LaTeX element it would not be output to Pages, so I've updated the macro to fix this.

This just goes to show that you'll need to test this on as many examples as possible!

2 Likes

FWIW, in such cases, I use Curio with LaTeXiT (although Curio supports LaTeX equations as well). Curio has a much wider range of options for types of content that can be added to the page and a broader definition of "free form layout".

--
JJW

Thank you very much for telling me a very fantastic editor.

I visited the site you mentioned, downloaded the program, and tried it for hours. And, unfortunately, I have identified a few trivial but important facts that the program does not fully support LaTex.

In particular, there was something I wasn't happy with about inline LaTex. It is more of a problem with my LaTex code itself than a problem with the program.

Anyway, I came back to Pages. It was a short but intense tour.
Thank you.

On my machine, this macro doesn't work (I can't hit the run button), maybe there's a problem with my machine settings. I will study the macro you gave me and update it.

THANK YOU!!

You will possibly need to enable the macro as usually they are installed disabled to prevent accidental (and malicious) usage. Check the box highlighted here:
CS Keyboard Maestro 2020-10-10 at 10.01.43

The problem is that you are trying to compile LaTeX equations and normal text all at the same time. The best option is to use a LaTeX application itself.

You are finding out that, when you work with components that have LaTeX, you have four options:

  • Manually enter the text and LaTeX into Pages (or another program), switching each time between normal text and LaTeX.
  • Create / find a (complex) macro that will do the above for you.
  • Learn LaTeX with a real LaTeX editor application, also learning how to put figures into the document.
  • Change your approach to separate the LaTeX math from the normal text and figures, for example so that you are not trying to run an in-line mode of compilation over an entire paragraph of input.

I will close with one example of a lecture slide that I generated in Curio to combine text, equations, mind maps, and pictures.

The equations are embedded using LaTeXiT, not with the equation editor in Curio (while it is good in its own right, it is only a recent addition to Curio, and I have a longer history of developing equations into Curio with LaTeXiT).

For the opposing view of paginated documents with text, images, and equations, you need only visit any one of the many journal articles in physics, chemistry, or other disciplines. Many of them have their source files generated entirely in LaTeX formats.

My recommendations in summary: If you are generating a paginated document, learn to use LaTeX directly. It is really not that hard to embed text, math, and images to that point that wrapping around figures is also possible. If you are generating a free-flowing document (what I might call a white board), learn to separate the components for math (LaTeX), normal text, images, and other content to be able to work properly with each tool.

Best of regards with your ongoing explorations.

--
JJW