Space around lists, quotations, etc.

Everything related to our flagship word processor.
chronodm
Posts: 6
Joined: 2012-09-06 15:53:40

Space around lists, quotations, etc.

Post by chronodm » 2019-08-08 12:24:38

I'd like to format lists, block quotations, and various other things such that there's no space between the list items (or between paragraphs in a block quotation), but there is a space between the list (or block) and the paragraphs before and after.
text.png
text.png (49.45 KiB) Viewed 4207 times
So far I have two solutions, but they both seem like bad hacks:
  • add an explicit blank line before and after the list or quotation
    create an extra style, in addition to the list or quotation style, that has spacing before, and apply that style to the first paragraph in the list, and likewise create another that has spacing after, and apply that to the last item in the list
In MS Word, there's an option "don't add space between paragraphs of same style", which allows you to configure say your blockquote style with "space before: 12pt" and "space after: 12pt"", but have it only apply when the previous (or following) paragraph is not part of the quote. But Nisus Writer Pro doesn't seem to have that option.
style.png
style.png (7.67 KiB) Viewed 4207 times
What's the most Nisus-like way of achieving this kind of formatting?

Vanceone
Posts: 143
Joined: 2013-05-03 07:06:31

Re: Space around lists, quotations, etc.

Post by Vanceone » 2019-08-08 12:36:27

While I too would like a better answer, your second "bad hack" won't work: only one paragraph style can affect a paragraph. You CAN manually override the "spacing before" and "spacing after" of a paragraph with a paragraph style, so in reality your second option would be to select the first line of your block quote and manually set the "space before ¶" to something higher. That's what I do, to be honest. It does fly in the face of what a style sheet should do, I agree.

As far as I know, the most automated way to do what you want would be to use the Macro language to find each paragraph of your block quote or list style, then see if the next paragraph is also the style and if so add space before the first paragraph.

There's no built in command to do what you want. Nisus DOES collapse the space before a paragraph and the space after a paragraph if both would be in effect, so that's something at least.

adryan
Posts: 310
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Space around lists, quotations, etc.

Post by adryan » 2019-08-08 17:45:23

G'day, Vanceone et al

I usually do the manual override thing too, but I thought I'd have a play with a quick-and-dirty macro approach. The following seems to work, for lists anyway. But note that it takes advantage of what I consider to be a bug; viz, that the Select Next in Style command, when used in conjunction with Lists and Paragraphs, actually selects previous material that is similarly styled as well. So this approach may not work for long. ;-)

Code: Select all

# We assume the insertion point is located somewhere in the list in question.

Format:Lists:Select Next in Style

# The following line sets the Paragraph Spacing at the end of the list.
Set Paragraph Spacing After 12

Find All @Text<\n.>, 'Esa'
Find All @Text<\n>, 'Esa'

# The following line sets the Paragraph Spacing between items in the list.
Set Paragraph Spacing After 4

Previous Selection

Format:Lists:Select Next in Style

Find ".(?<=)", 'Es'

# The following line sets the Paragraph Spacing before the list.
Set Paragraph Spacing Before 12

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

chronodm
Posts: 6
Joined: 2012-09-06 15:53:40

Re: Space around lists, quotations, etc.

Post by chronodm » 2019-08-08 18:42:34

Thanks for trying. I came up with another hack: if you don't need more than 8 points of space before or after, you can fake it with a white table border.
table-list.png
table-list.png (31.54 KiB) Viewed 4177 times
table-palette.png
table-palette.png (4.36 KiB) Viewed 4177 times

adryan
Posts: 310
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Space around lists, quotations, etc.

Post by adryan » 2019-08-08 21:08:58

G'day, chronodm et al

Full marks for creativity!

However, as I think has been discussed in another thread, Tables become problematic when they straddle page breaks (virtual or otherwise). In the case of a single-row Table — which is what is required for simplicity in the present context — the entire Table (and its contained list) must fit on a single page. Long lists — or even short ones with large font sizes — can cause difficulties. As well, any number of things could end up pushing the Table down to another page, potentially leaving unsightly white space in its wake.

Another possibility would be to insert invisible Shapes of some sort above and below the list, but I mention this only to dismiss it as impractical.

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

Þorvarður
Posts: 277
Joined: 2012-12-19 05:02:52

Re: Space around lists, quotations, etc.

Post by Þorvarður » 2019-08-09 05:32:04

chronodm wrote:
2019-08-08 12:24:38
What's the most Nisus-like way of achieving this kind of formatting?
Unless I've completely misunderstood the question, this should be fairly easy to accomplish. Besides the "Normal" style, you need two new styles: a quote paragraph style and a list style, i.e. if paragraphs containing the quotes must have numbers, like in your screenshot.

Keep in mind that the space between (quotation) paragraphs is determined by the paragraph style, not the list style.

So, if you want the quotation paragraphs to have numbers and you also want to be able to control the space between the paragraphs, your quotations must combine the two styles: the quotation paragraph style and the list style being added to it; or we could also say, a list style and a quotation paragraph style added to it. It doesn't matter which way you look at it.

1) Your "Normal" paragraph style should have Space Before and Space After set to, let's say, 6 pt.
2) Your block quotation paragraph style should have Space Before and Space After set to 0 pt.

Now all you have to do is to select the block quotation text and assign it the block quotation paragraph style, and then, when that's done, add the list style to it.

Now, to add the paragraph style and the list style simultaneously, we would use a simple macro with a convenient keyboard shortcut:

Code: Select all

Format:Paragraph Style:Block quotation with no space between paragraphs # [= the name of your block quotation style]
Lists:1. # [= the name of your list style]
Does this solve the problem?

adryan
Posts: 310
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Space around lists, quotations, etc.

Post by adryan » 2019-08-09 06:48:58

G’day, Þorvarður et al

If I’ve understood you correctly, Þorvarður, essentially what you’re doing is getting the paragraphs immediately preceding and following the block (consisting of one or more paragraphs which could represent a quotation or a list or whatever) to do the work of space-setting above and below the block.

This is all very well, but things can get a bit complicated in at least a couple of scenarios.

One is when you want the block to be offset (vertically) from surrounding text by a larger distance than the usual paragraph spacing for that (“normal”) text.

Another is when the block follows or precedes some non-standard element such as a Shape or a Table.

We really want the preceding, intra-block and succeeding spacing to be determined by a Style specific to the block, independent of Styles applicable to surrounding elements. Ideally, then, NWP needs to have, in addition to Paragraph Styles, a new class of Style — viz, a Block Style.

Pending the incorporation of such a feature, I think a macro that focusses just on a block’s intrinsic components is what is required. My own attempt exploited what I believe to be a bug, but someone with more facility with the macro language than I may be able to devise a more robust solution.

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

martin
Official Nisus Person
Posts: 4605
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin » 2019-08-09 14:00:22

This is certainly an area that could be improved in Nisus Writer. It would be great if before/after paragraph spacing could be controlled situationally by paragraph styles. That option in Word to suppress spacing between paragraphs in the same style is one way to improve things, but it would be even better if spacing could be conditionally and automatically controlled for all style combinations.

CSS from the web has tools for this, so you can configure a stylesheet so that when style A is followed by style B, you can enforce custom spacing (or other attributes). Arbitrary rules are allowed so you can customize not only (A + A), (A + B), and (A + C), but also (B + A) and other reversals.

We already have an enhancement request filed for this, but I'll upvote it. Hopefully it's something we can get to sooner.

martin
Official Nisus Person
Posts: 4605
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin » 2019-08-09 14:05:47

chronodm wrote:
2019-08-08 18:42:34
I came up with another hack: if you don't need more than 8 points of space before or after, you can fake it with a white table border.
As Adrian said, that's certainly creative! But as other pointed out, it's going to be much easier if you just add some spacing manually, to override your paragraph style(s).

If you have this situation a lot in your document, you could add a few new paragraph styles, eg: add a style called "List Style (First Paragraph)" that's based on your existing style but with additional spacing beforehand. This isn't terribly elegant as the number of styles in your document increases, but sometimes it's a palatable workaround.

martin
Official Nisus Person
Posts: 4605
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin » 2019-08-13 08:43:26

Here's an example file that shows the technique of using specialized paragraph styles to control list spacing:
lists example.rtf
(24.51 KiB) Downloaded 68 times
The file has a paragraph style called "List" that enforces the list style called "Number List" and eliminates the spacing between paragraphs. This style is the basis for the other two list styles, called "List - First" and "List - Last". As you might have guessed these styles are applied only to the first and last paragraphs in a sequential list. They have been specialized to enforce spacing around the list.

A few points about working with this setup:

1. To start a list in your document text just apply the paragraph style "List - First".
• That style enforce list numbering (1,2,3). To use a different numbering type you'll need to apply another style, eg: "Lettered List".
• If you type return after the first paragraph in your new list, the style will automatically switch to "List".
• Continue adding new items to your list by typing; the "List" style remains applied.

2. After you're done adding items to your list, apply the style "List - Last" to the final paragraph.
• Typing return after that final paragraph will automatically switch you back to the "Normal" paragraph style.

One final thing that's always good to consider: you can customize your keyboard shortcuts in the Menu Key preferences to make this workflow very efficient. If you assign (for example) Command + L to the paragraph style "List - First" then it's very convenient to start a new list. Likewise it's nice to have a shortcut for the style "List - Last"; I actually use Command + LL (with two L's) as a mnemonic for "last". That way your hands never leave the keyboard when you're typing up a new list.

adryan
Posts: 310
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Space around lists, quotations, etc.

Post by adryan » 2019-08-13 14:36:07

G'day, Martin et al

It should be possible to achieve differential spacing before, within and after a block of text without the need to create more Styles.

Part of my difficulty in trying to automate that spacing was that I could find no quick way of navigating to the first and last paragraphs in a list without having to resort to the more sophisticated commands available in the macro language. I wanted to employ regular expressions in the Find & Replace system instead.

Actually, it's easy enough to find the beginning of such a block of text in this way, but I could think of no reliable way to find its end, especially when one considers situations in which a final paragraph return may or may not have been selected or even exist. In this respect, it would be very useful to have "Start of Selection" and "End of Selection" available as Special Positions in the cogwheel drop-down menu of the "Find what" field.

So what I thought of doing was to delimit the selection with dummy strings that would be unlikely to occur elsewhere in the document. It would then be easy to find each of these dummy strings (and hence the first and last paragraphs), adjust the Paragraph Spacing Before or After as required, and then remove the dummy strings. Incorporating the required commands in a macro is also easy. Note that this procedure confines itself to the block in question, in accordance with the recommendation I made earlier. And it does not require any special Styles to be defined.

This method does in fact give the required padding above and below a block while retaining the original paragraph spacing within the block. It works, too, when the block consists of a List. Unfortunately, it can mess with the List Style. One might be able to work around this if there were Copy List Style and Paste List Style commands available, but there are not. (It would be nice, too, if similar commands were available for Character, Paragraph and Note Styles.)

The real problem is that Find & Replace does not necessarily take cognizance of List Style. I will refrain from taxing us all further by elaborating on the various combinations I have tried. Some remove the List Style entirely, while others superimpose a List on the existing one (by which I mean that you end up with two tab-separated numbers for each List Item in a Number List). List Levels are not respected, in that all List Items end up at the same Level, if you end up with a List at all. I observe that, if one selects the contents of the Find field and applies a List Style from the Format menu, the Formatting Sensitive checkbox automatically becomes ticked, so some expectation is induced that List Style will be preserved.

It may be that there is something I do not understand about the intended behavior, but I could find nothing pertinent in the User Guide.

The behavior I expect is as follows: If all of the following three conditions are met:–
(1) a selection is confined to a subset (proper or otherwise) of a block of text subject to a List Style
(2) the Find expression (in the "Find what" field) has the List Style applied to it (via the Format menu)
(3) Find In Selection has the Formatting Sensitive checkbox ticked,
then (assuming Find has been successful) Replace should, with the Replace Formatting checkbox unticked:–
(a) apply the List Style to the replacement text
(b) preserve the List Style for any text that was subject to it previously
(c) preserve List Levels insofar as this is possible. I won't give the full specification here, but the principal idea would be to give precedence to any paragraphs outside the selection: their List Level should remain unchanged, even if part of the paragraph was included in the selection. How List Levels are assigned to paragraphs entirely within the selection would require a bit more thought because the replacement text may include a different number of paragraphs, but the aim would be to make reasonable assumptions that minimize the need to manipulate List Levels of individual paragraphs manually.

All of this could be done with a macro, but my point is that things seem to come unstuck when Find & Replace is applied to Lists. Of course, Lists are a very special type. However, in the absence of a caveat applicable to this situation, there should at least be some documentation of the designed behavior. But ideally Lists would be handled along the lines I have suggested above. And chronodm’s original problem could be solved fairly easily.

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

User avatar
phspaelti
Posts: 1042
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Space around lists, quotations, etc.

Post by phspaelti » 2019-08-13 18:09:46

Hello Adrian,
While I understand what you are trying to do here, I really think that once you get into the thick of using macros to accomplish such complex tasks, you should get over your aversion to using the macro language. Basic Find and Replace is fine for simple editing macros, and making selections, but I just wouldn't use it to enter markers for editing locations that you later want to remove. Conceptually it just feels wrong to modify your document in that way, even if the effects are harmless. And as you discover here the effects are not harmless. (For similar reasons I really try to avoid macros that use replace across unrelated text, because I "don't trust" the respect formatting option. Of course it works fine. But I still try to avoid it.)

I have so far refrained from joining this conversation and adding a macro solution, because in the end the approach will depend on which choice of interface you want. Do you want a macro that affects just the current list, or applies to all lists at once? Do you want to use preset spacing, or allow the user to set spacing at run time? Do you prefer working with the list styles directly, or set list styles via paragraph styles? And also do you want a "smart" macro that works correctly even for a "dumb" user (i.e., correctly covers all limit cases), or just works well enough for your own purposes (perhaps a one-time clean up macro).

So here is some code that shows how you would select the first/last paragraphs of each block of list style text. As I tend to prefer, I write this using fewer intermediate variables. But you can write the whole thing more "step-by-step" if you prefer.

Code: Select all

# Get the list style
$doc = Document.active
$listStyle = $doc.textSelection.listStyle

# Find first and last paragraphs for each list style block
$firstSels = $lastSels = Array.new
foreach $sel in $doc.text.find($listStyle, 'a')
    $firstSels.push TextSelection.new($sel.text, $sel.text.rangeOfParagraphAtIndex($sel.location))
    $lastSels.push TextSelection.new($sel.text, $sel.text.rangeOfParagraphAtIndex($sel.bound - 1))
end

# Apply formatting to respective bits
$doc.setSelection $firstSels
Set Paragraph Spacing Before 6
$doc.setSelection $lastSels
Set Paragraph Spacing After 6
philip

adryan
Posts: 310
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Space around lists, quotations, etc.

Post by adryan » 2019-08-14 01:56:23

G’day, Philip et al

Thanks for getting involved in this topic, Philip.

I understand your philosophical objection to the (albeit temporary) document modification I propose, but I don’t mind using such tactics if all else fails.

One of my philosophical approaches to programming is to strive for generality of application, if that’s at all possible. My proposed solution to this spacing problem is meant to cover blocks of text in general, be they Lists, quotations or whatever. All we are trying to do is alter two spacing parameters; everything else should remain as it was. A single, simple macro should be all we need.

I’ve thought about what you said, and done the odd experiment, and I’m coming to the conclusion that you may well be right about expecting too much from Find & Replace.

But can we revert to my original question: Is there a way to position the insertion point in the final paragraph of a selection using Find & Replace?

For example, the following code works inconsistently:–

Code: Select all

Find "^.", 'Es'
Set Paragraph Spacing Before 12
Previous Selection
Find "^.", 'EsrW'
Set Paragraph Spacing After 12
I think the problem lies with the Selection stack. It would be nice to have some way of clearing it.

If it is just not possible to get Find & Replace to do this, perhaps we might prevail upon you, Philip, for a simple Style-agnostic macro that operates on the first and last paragraphs of a selection, whatever it may be. Unfortunately, your List spacing macro as it stands does not preserve List Levels.

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

martin
Official Nisus Person
Posts: 4605
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Space around lists, quotations, etc.

Post by martin » 2019-08-14 08:16:45

adryan wrote:
2019-08-14 01:56:23
For example, the following code works inconsistently:
...
I think the problem lies with the Selection stack.
There is indeed a problem with the selection stack/history that's preventing your macro from working correctly. It looks like the current selection (at the moment when you start the macro) isn't being committed to the history before the macro starts running. Because of that the macro will restore a selection that's one step older than desired.

I'll file this as a bug to get fixed. Thanks for bringing it to my attention Adrian.

You can pretty easily adjust the macro to work around this issue. Instead of using the selection history commands, just do it yourself directly in the macro, eg:

Code: Select all

$doc = Document.active
$selection = $doc.textSelection
Find "^.", 'Es'
Set Paragraph Spacing Before 12
$doc.setSelection($selection)
Find "^.", 'EsrW'
Set Paragraph Spacing After 12

adryan
Posts: 310
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Space around lists, quotations, etc.

Post by adryan » 2019-08-14 14:16:16

G'day, Martin et al

Thanks heaps for that, Martin.

As far as I can tell, this pretty much solves chronodm's original problem. The only caveat is that the selection must commence with a Paragraph Start. (But it can finish anywhere within a paragraph, with or without a paragraph return.) I had a look at the Macro Language Reference, but it wasn't immediately apparent to me how to deal with this (relatively minor) limitation. The main reason for addressing it would be to permit more forgiveness in the selection.

I would suggest that such a macro would be useful enough to bundle with the included macros, perhaps in the Editing folder with a name such as "Pad Text Block".

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

Post Reply