Page 1 of 1

Shortcut for Headings

Posted: 2015-02-02 03:03:57
by Chrow
Is there a way to add a shortcut that inserts a heading-paragraph based on the level of the last heading-paragraph used in the document?

For example:

Code: Select all

1. This is a Heading

this is some text
now I use a "level-down" shortcut and it results in

Code: Select all

a. next Heading
So you would only need 3 shortcuts (level up, down and same level) do enter the headings.

Regards
Chrow

Re: Shortcut for Headings

Posted: 2015-02-02 05:26:16
by phspaelti
One could write a macro to do this.

----------------------
The following two macros will do one level up and down respectively.
[Attachment removed. See below]

Re: Shortcut for Headings

Posted: 2015-02-02 10:17:57
by Chrow
Wow, thanks!
I thought that there might be a possibility without macros or I'd have at least tried to code it myself. :lol:

I changed the macros to make them compatible with the german Nisus version and added one to add a heading on the same level as the las one. But I can't seem to get rid of those two warnings at the beginning:

first one: unknown path of @undefined
second one: attempt to define variable with a command that doesn't return a value
(loosely translated from german version)

I am pretty sure that the best solution would be to replace @undefined in line 12 with the value $lastHeading would have, if the last Heading was a Heading 1. But I'm not able to find out what that is/ how to do that.

Regards
Chrow

PS: I know this does not belong in here, but since it is my own thread I am gonna misuse it for a second: Does anyone know what the macro-command for "put x in a footnote is?" because I am working on a macro that puts every {...} in the document in a footnote.

Re: Shortcut for Headings

Posted: 2015-02-02 20:52:11
by phspaelti
Chrow wrote:But I can't seem to get rid of those two warnings at the beginning:

first one: unknown path of @undefined
Sorry about that. Yes, that @ symbol should be removed. It should just be "undefined".
Chrow wrote: second one: attempt to define variable with a command that doesn't return a value
(loosely translated from german version)
That is the 'border' case. It happens if you try to run the macro without any previous heading. For that you really have to decide what kind of behavior you want from the macro. I generally prefer a 'light' style, where I don't make the macros 'idiot-proof', since I am just using them for myself, and I presumably know what I'm doing :P But I have now re-written them so that they (a) insert 'Heading 1', if no previous style is found, and (b) do nothing if there are no heading styles in the document.
I have also changed them and added a single line with the prefix near the beginning of the macro. You can just uncomment the German one (with "Überschrift").
Heading Up_Down.zip
(7.79 KiB) Downloaded 426 times
Chrow wrote: PS: I know this does not belong in here, but since it is my own thread I am gonna misuse it for a second: Does anyone know what the macro-command for "put x in a footnote is?" because I am working on a macro that puts every {...} in the document in a footnote.
There should already be a bunch of macros around that can do this, but, by all means, try writing your own. If you look in the macro reference (in the Help menu), you will find the following:

Code: Select all

Note.insertFootnoteInTextAtIndex text, charIndex, [noteContent]
which will do what you want. If you have any questions, just ask. But perhaps better in a new thread, in the macro forum. :wink:

Re: Shortcut for Headings

Posted: 2015-02-02 21:39:57
by phspaelti
Chrow wrote:I thought that there might be a possibility without macros or I'd have at least tried to code it myself. :lol:
Well, actually I just wrote a macro for this because I'm lazy :P

But after thinking about it a bit more, I am pretty sure that you need to write a macro for this, since what you are looking for is a bit more sophisticated. Nisus does have some nice features that come close in this area. What you can do, is easily promote and demote headings in the Navigator. So if you open the Navigator and select the relevant heading, <tab> will demote it and <shift-tab> will promote. This is similar to what you can do with list styles, where the "Increase/Decrease Indent" commands, become "Increase/Decrease List Level" (and <tab>/<shift-tab> work as well). But of course in either case you will have to insert the relevant heading/list item first, and in the case of headings you will also have to move the focus to the Navigator first as well. Neither will work backwards across other content in an intelligent fashion.