Tab to user created field

I would like to implement the following functionality. I have the following LaTeX

\begin{bmatrix}
%|% & %< … >% & %< … >% \
%< … >% & %< … >% & %< … >% \
%< … >% & %< … >% & %< … >% \
\end{bmatrix}

I have my cursor at the first position and would like to use the Tab key to move the cursor to replace the %<…>% text. Is there a clean way to do this?

I'm not sure exactly what you mean by this. Please clarify.

Please post exactly what you want after the movement and replacement.
I'm not sure if you mean just the first occurrence, or all occurrences of %<...>%

I expect this to be easy, using Type a Keystroke Actions and a simple Search/Replace using RegEx. But I need to be clear on exactly what you want first.

Thanks for the reply Michael.

The syntax %|% is one of the commands to place a cursor. What is supposed to happen is that once I type command+m (the apple command key and m) this text appears:

\begin{bmatrix}
%|% & %< … >% & %< … >% \
%< … >% & %< … >% & %< … >% \
%< … >% & %< … >% & %< … >% \
\end{bmatrix}

The cursor is moved to the location where %|% is. In text typed above, the ampersand is a delimiter so that a matrix is created. What I want to do is to type something at the location %|% and then press Tab. When I press Tab the text %<…>% is highlighted so that when I type anything that text (the %<…>%) is deleted. Then, when I press tab again this process is repeated to fill all the spots, one by one.

The %<…>% is really just a placeholder field that I want to replace with anything that I type. The point of the Tab I suppose is to highlight the next %<…>% encountered.

Thanks!

What app are you using when you do this?

Some apps, like Script Debugger, are designed to have place holders and perform much like you described. But not all apps have this feature.

I'm thinking BBEdit might, but I'd have to check first. You might look at BBEdit to see if it is of any help to you.

Yep, BBEdit does support placeholders. See:
BBEdit ClippingPlaceholderReference

I've never used this feature, so I don't know for sure that it will do what you need.

I’m actually doing this on Overleaf in the Safari browser and on TeXStudios.

OK, I don't know anything (never even heard of) either of those apps.

So, I'm assuming that Overleaf does not support placeholders, correct?
And you want to build a KM macro that does, correct?

I think the choices are:

  1. Build a complex completely in KM that finds each placeholder, and allows your replace it.
  2. Use BBEdit

The text you posted, is this just something you made up?
Are the number of placeholders fixed, or do they vary?

If fixed, it would be very simple to present a Prompt for User Input with one KM Var for each placeholder, and then generate the required output string.

Again, it would be really helpful if you would post EXACTLY:

  • The text BEFORE changes, with the placeholders.
  • The text AFTER you have made the changes.

How about this. Is there a way to move the cursor ahead several characters? For example,

1 some text some text 1 some text some text

the cursor starts at 1 but I want to move the cursor to the next 1 on the page.

Not sure if I understand what you want. But if the %<...>% are just placeholders you could build a simple boilerplate macro like this:

__LaTeX Boilerplate.kmmacros (3.9 KB)


In the User Prompt you can move with the Tab key from one input field to the next. Once you hit Return the text gets copied to the clipboard.

Because of the backslashes, make sure to set the Set Clipboard action to “Process Text Tokens Only” (gear icon):

Yep, that is exactly what I was suggesting here:

Of course, the key question is whether or not there are a fixed number of placeholders.

Of course there is. I already mentioned that.
But that won't solve your whole problem, as I understand it.

Until we see this, anything posted is just a big guess.

Hey @Grenix

Of course.

The problem is that that macOS does not allow access to arbitrary text editing venues, so it's not possible to get information about them or move the cursor to a desired position in an organic way. (Unless the given venue (app, field, etc) is highly scriptable.)

The only way is to copy existing text, find what you're looking for and then force the UI to move the cursor. It's clunky and slow, but it can be better than doing things manually under some circumstances.

One thing you can do is to use the Set Find Pasteboard action to set the system find pasteboard to text you want to search for such as:

 %<...>%

Then G to the next field.

This will work in Safari and any app that uses the system's find pasteboard.

-Chris

2 Likes

Huh. You learn something every day! :slight_smile: