I’ve finally abandoned windows and moved to linux. ( I was an hp-ux unix workstation user and sysadmin.) I’m having a problem in writer doing my usual work. I have been building outlines in xmind (mind maps), copying them, pasting them into ms-word, selecting them, making them an outline list and printing them for around 15 years. I print them a couple times a week and the process of going from mind map to printed list takes me 2 minutes tops. I just cant seem to make this work in LO Writer.
The format that comes from xmind is plain text with tabs at the beginning of each line indicating the indent level. (lines can be as short as a word or two, or as long as a long paragraph at times.)
I have tried everything I can think of but nothing has worked except formatting each line one by one. I’ve spent endless hours reading the manual and lists to no avail. Can someone point me in the right direction? I can see there’s a massive paradigm shift coming to LO.
I used to be a software guy and will be porting some of my formatting macros over an have no worries about learning the scripting language for LO if that’s the way I’ll need to go here.
Anyhow, thanks in advance for any pointers.
does it have anything to do with this post?
Thank you for the link; My issue is not related to table of contents but creating numbered lists in the content itself from text with leading tabs.
with a macro you could proceed in this way:
Define as many paragraph styles as there are indent levels by formatting them as list styles, each for each level of hierarchy provided
scan list of tabbed paragraphs using the enumeration technique. At each iteration you will get a reference (for example, oPar) to the current paragraph
for each paragraph execute s = oPar.string to extract the text of the paragraph
Use the string functions to count the number of initial tabs
the found count shows you which style to use to format the paragraph with the required list style
Yes, that was my thinking if there was no automatic way like ms-word has. If possible my macro will read what is in the copy buffer and insert it line by line after parsing and formatting it. (I use some simple markdown codes in xmind since it doesn’t support any kind of rich text in it’s nodes. I’m so happy I have access to real regexp’s and not be using that MS abomination) Guess I’ll need to roll up my sleeves and start programming in LO.
I still don’t understand LO’s “Style” system. To do this cross-document will my personal styles automatically go to all docs or will I need to use a template document or will my styles need to be embedded in the macro itself? Do I really need one style per indent level or do I use one style for the list and just set the indent level for each paragraph?
You need only that the styles to be applied for each hierarchical level have previously been defined as user (personal) styles if standard styles cannot be used (I think the “list 1”, “list 2”, … standard styles , modified properly, may suffice, but not if I’m sure)
Why would you use one para style per level (even when configured for list)? List in Writer are multi-level. One para style is enough. The trick is to tell Writer at which level text should go. Manually, you do that by pressing n-1 times
Tab key for level n with the cursor at head or paragraph. I don’t know how this translates in a macro because these
Tab characters are not kept as text.
By manually inserting the tabs, LO recognizes the insertion of a hierarchical list.
The problem here is that the list is already encoded as text with leading tabs. And these leadings tabs, from the few tests I performed, are NOT recognized as a hierarchical level indicator.
If this were not the case the problem would have already been solved.
When I tried to apply to the text with leading tabs the general style of multilevel list I got only a single-level list, where each line kept the original leading tabs.
For this I provided a working code, leaving open which styles to apply, hoping that other users would complete the answer.
LO provides standard styles like “list 1”, “list2”, “list 3” …
For now it is the only idea I have about the possible styles to apply.
For now it is a partial answer, the code work, but it need the correct style definition before, here named “tabList1”, “tabList2”, and so on
This code reads a document containing only the sequence of tabbed paragraphs to be converted
For each paragraph, get the leading tab number and use it to define the name of the style to be applied
It is not yet clear to me how each style should be defined, before starting the macro, to correctly format each paragraph based on the hierarchical level.
If you had to transform the tabbed paragraphs into a heading list (outline) using the default styles “heading 1”, “heading 2”, “heading 3” you would have already solved the problem
It is not clear to me whether it is sufficient to use the predefined styles “list 1”, “list 2”, etc.
sub tabbed() d=ThisComponent sStyle="tabList" e = d.Text.createEnumeration() 'com.sun.star.container.XEnumerationAccess c=0 Do While e.hasMoreElements() oPar = e.nextElement() If oPar.supportsService("com.sun.star.text.Paragraph") Then s=oPar.string i=0 do while mid(s,i+1,1)=chr(9) i=i+1 loop sStyleName=sStyle+cStr(i) oPar.paraStyleName=sStyleName c=c+1 end if Loop end sub
Edit 10 november 2019
The right solution is :
sub tabbed() ' text tabbed pasted in a first document section d=ThisComponent oSecs=d.textSections oSec=oSecs.getByIndex(0) ' use another section index if you want sStyle="Numbering 123" tc=d.text.createTextCursorByRange(oSec.Anchor.getStart()) tc.gotoRange(oSec.Anchor.End,true) e = tc.createEnumeration() 'com.sun.star.container.XEnumerationAccess c=0 Do While e.hasMoreElements() oPar = e.nextElement() d.currentController.select(oPar) If oPar.supportsService("com.sun.star.text.Paragraph") Then s=oPar.string d.currentController.select(oPar) i=0 do while mid(s,i+1,1)=chr(9) i=i+1 loop oPar.string=right(s,len(s)-i) oPar.NumberingStyleName=sStyle oPar.numberingLevel=i ' oPar.paraStyleName=sStyle+cstr(i) c=c+1 end if Loop e = tc.createEnumeration() oPar = e.nextElement() oPar.ParaIsNumberingRestart=true ' reset numbering root element list oPar.NumberingStartValue=1 end sub
The solution goes in the direction indicated by @ajlittoz, the problem was that it was not absolutely clear how to do it via macro
In my first tests I had tried to do so by assigning the name “Numbering 123” to the name of the style of each paragraph, but it was the wrong place
Properties needed to be changed are:
(oPar) .NumberingStyleName = sStyle ' "for example "Numbering 123" (oPar) .numberingLevel = level number calculated from leading tabs
And it has its own logic, because list styles add list properties to the paragraph style
The only thing missing is the reset of the numbering on the first paragraph in the root of the list. There is a property to do it automatically, maybe I add it later, it’s very simple.
If you think this is the solution you wanted, you can check the solved flag
Further to my comment under your question: by using tabListn styles, you end up with n 1-level lists. As you rightly remarked, you must remove the
Tab characters otherwise they appear as text. Not being familiar with macros (not at all in fact), I don’t know how you assign a level to a list item. This is the core point of the problem.
You could also use built-in Listn after associating them with a so-called list style because, out of the box, they are simply paragraph styles without the list property.
The assignment of a style already defined manually or created and defined with a macro is already provided in my macro with the code instruction oPar.paraStyleName = sStyleName
Clearly this instruction assumes that there is a style and therefore a style name (sStyleName)
As for the tabs to be deleted, simply enter this code after the while loop:
oPar.string = right (s, len (s -i) (be careful, formatting is lost)
The real problem is finding a multilevel list-style or a series of list-styles, one per level (I think we use the default styles “list 1”, “list 2”, etc. but I don’t have the time to verify it)
@torreone: “restart numbering” is not an attribute in paragraph styles. This is one of the rare direct formatting actions remaining in Writer. You’ll have to find the macro equivalent of
but this code work
oPar.ParaIsNumberingRestart=true ' reset numbering root element list oPar.NumberingStartValue=1
Very good! You apply it in a designated paragraph, just like you would with direct formatting. Don’t forget to remove the “The only thing missing …” paragraph in your answer now that everything is in place.
Very Thanks, I had forgotten to delete that note. Now I have a clearer idea of what the most important properties for macro management of lists and list styles are.
I need you for the future. Starting from an observation by @mikekaganski of the past few days I have developed a seemingly working code for multiselection of text segments.
I will soon open a discussion on this