Sections and subsections are the building blocks of any well-structured document. You’ve likely used them countless times, perhaps without even realizing it, as every document contains at least one section by default!
Whether you’re a seasoned pro or just starting out, this post will walk you through the basics of sections and subsections.
We’ll also explore the exciting new 4D Write Pro features in 4D 20 R7, which make managing these elements easier and more powerful than ever.
Getting to Know Documents, Sections, and Subsections
If you’re already familiar with these concepts, then feel free to skip ahead. For everyone else, let’s cover the basics.
As we said in the introduction, a document contains at least one section. If it contains more than one, they are separated by section breaks (we’ll return to this later).
the document
Let’s start with the document itself. It can be configured using a whole host of attributes such as padding, paper size, background color, borders, etc.
Sections
Sections are segments within your document that can inherit its properties, such as background color and margins. By default, sections mirrors the document’s attributes unless you specify otherwise. Each section can also have its own header and footer.
subsections
Unlike sections, subsections only exist if you create them. But what exactly is a subsection?
There are two types: Different first pages and Different left and right pages. Just like sections inherit attributes from the document, subsections inherit attributes from their parent section—until you decide to make changes.
Visualizing Sections and Subsections
The document above contains 4 distinct sections:
- Section One: A green background with a header.
- Section Two: A “Different First Page” with a dark blue background and no header.
- Section Three: A “Different First Page” without a header and “Different Left and Right Pages” with headers.
- Section Four: Two columns with a footer and identical first, left, and right pages (no subsections).
Finally, the first three sections have a section break (represented by red dashes) at the end of the section, while the fourth does not (i.e., there is no fifth section).
All these features, whether for sections or subsections, are stored in internal storage, whether defined via the interface or programmatically.
Everything described above is available in many versions of 4D Write Pro. Now, let’s move on to the new features!
Introducing New Features in 4D 20 R7
Deleting sections
Until now, managing sections might have seemed straightforward, but it was more complex.
Sections in 4D Write Pro don’t have unique internal identifiers; they are indexed based on their position in the document. When you delete a section, the indexes of all subsequent sections shift accordingly. If you only remove the section break, the sections merge, which often results in unexpected formatting changes. This challenge isn’t unique to 4D Write Pro—it’s common across many word processors, including Word and Pages.
A new command
Deleting a section is now child’s play, as a new WP DELETE SECTION command allows you to delete sections without causing these issues. This command ensures a complete deletion of the section’s content and characteristics, preventing any unintended merging.
Remember, however, that a document always contains at least one section. A document must have at least two sections for this command to be usable.
Samples:
Deletion of section 4 of the document (assuming the section 4 exists, otherwise an error shall occur)
WP DELETE SECTION ($document;4)
You may want to delete more than one section… then add the number of sections to be deleted.
WP DELETE SECTION ($document;4;3)
A new standard action
This feature is also available as a standard section/remove action. It can be used in your interface as a button or menu item. The only difference with the command are:
- Its use will be followed by a confirmation of deletion (remember: a section can be large and voluminous).
- Only one section can be deleted at once (the first one intersecting the user selection)
That said, even after an unintentional deletion, the previous state can be regained thanks to an “undo.” That’s magic.
So what happens in depth?
When you delete a section, here’s everything that’s deleted:
- The part of the document body contained in the section
- The headers and footers of the section and any subsections
- Images and textboxes anchored to the section
Please also note that the indexes of subsequent sections are decremented, so the anchor numbers of images and text boxes affected by this deletion are automatically decremented, too. So you don’t have to worry about it – 4D Write Pro does it for you!
Pages disappear, but images may remain IN THE DOCUMENT
There is one exception, however, which you’ll need to take into account: if an image or textbox is anchored to a page (let’s say page 20) and this page no longer exists after a section has been deleted, the image (or textbox) will remain in the document… and will reappear on page 20 if this page ever exists again later.
Deleting a subsection
Since 4D 17 R3, you can delete a subsection using the WP DELETE SUBSECTION command. As its name suggests, it deletes either the “distinct first page” or the “distinct right and left” pages. This time, what’s deleted is different and has been improved.
As previously, the content (body) is never deleted, but headers, footers, and all styling options (frames, margins, background color, etc.) are deleted.
So what’s new?
Images and text boxes anchored in these subsections are also deleted, so do not expect to see them reappear if you recreate them. You’ll have to recreate the headers, footers, images, and text boxes anchored to them. Only an “undo” (magic!) will restore you to the original state when performed right after the deletion.
Everything described above applies whether you’re working with programming or using the interface. Unchecking the “Different First Page” or “Different Left and Right Pages” options produces the exact same result as removing the subsection through programming!
WP DELETE SUBSECTION($section; wk first page)
WP DELETE SUBSECTION($section; wk left page)
Resetting attributes
Now we come to the most interesting part of the new features.
As a quick reminder, section and subsection attributes, when undefined, are inherited from their parents. For a section, these are the attributes of the document; for a subsection, they are those of the section itself.
The WP RESET ATTRIBUTES command has been modified to allow you to simultaneously delete all the attributes of a section or subsection. In this case, simply give the section or subsection parameter to the command but do not enter any attribute name, and they will all be deleted!
WP RESET ATTRIBUTES ($section) // all attributes of the section shall be reset!
WP RESET ATTRIBUTES ($subSection) // all attributes of the subsection shall be reset!
PRACTICAL EXAMPLES
You’ll remember that the first section had the essential feature of a green background…
If we remove the attributes of this section, the background will revert to white, which is the document’s background color. Remember: The section attribute no longer exists! It’s all about inheritance. If the document background subsequently turns gray, the section will be gray, too!
before reseting attributes ➼ after reseting attributes
The second section had a different first page subsection. What does that involve?
If we delete the attributes of the second section, the light blue background will also revert to white, except for the different first page, whose background has been explicitly defined as dark blue.
before reseting attributes ➼ after reseting attributes
If, on the other hand, you want the first (different) page to have the same background color (light blue) as the rest of the section, you need to reset the background color attribute of the “different first page” subsection.
WP RESET ATTRIBUTES ($subsection;wk backgroundColor)
Similarly, it’s possible to remove all overrides from this subsection so that it inherits the attributes of the section it depends on…
// no attributes = all attributes !
WP RESET ATTRIBUTES ($subsection)
The third section, which has a different first page and different left and right pages, will not lose any of its background colors when a WP RESET ATTRIBUTES is applied to it.
This is because the subsections have specifically defined background colors. They will therefore remain yellow, since they don’t inherit from the section (at least for this backgroundColor attribute).
before reseting attributes ➼ after reseting attributes
I’d like to take this opportunity to point out (or remind you) that although right/left subsections cannot (obviously) exist without each other, they are nevertheless independent. They can have separate attributes and, therefore, be reset independently of each other!
$subSection:=WP Get subsection(WP Get section($document; 3); wk right page)
WP RESET ATTRIBUTES($subSection)
$subSection:=WP Get subsection(WP Get section($document; 3); wk left page)
WP RESET ATTRIBUTES($subSection)
before reseting attributes ➼ after reseting attributes
Finally, the same command applied to the fourth section will reset its format to portrait mode with a single column (as in the original document).
before reseting attributes ➼ after reseting attributes
New interface item
The latest toolbar and sidebar updates include a new button with an associated menu for deleting sections or resetting their attributes. These tools provide context-specific actions based on your cursor’s position in the document.
Conclusion
We hope this post has deepened your understanding of sections and subsections in 4D Write Pro. With the new commands and interface enhancements, you can now fine-tune your documents with greater precision and style. As always, we encourage you to share your thoughts and experiences on the forum!