[Solved] Taking note and tagging format

Discuss the word processor
Post Reply
User avatar
StefArma
Posts: 2
Joined: Wed Feb 22, 2017 10:24 pm

[Solved] Taking note and tagging format

Post by StefArma »

Greetings community,

As first post i would like to introduce myself as well: I'm Stef, 25, Italian(I prefer english speaking communities), pharmacy student, PC gamer, guitar/music lover.

I always take notes by PC and tried different ways to achieve good and easy-reading text among which the best is Google Docs cooperating with multiple users (one write, another correct, another format). Anyway it happends i'm by myself and writing at speech speed + formatting might be hard.
In my point of view, format is more about tagging different kind of elements inside my text rather than paragraph defining. I make myself clear: a biochemistry text might include substrate, enzymes, co-enzyme, products, reading and visually recognizing each of them is lovely when reviewing on the train back home.
our well known friends:
Ctrl+b = bold,
Ctrl+i = italic,
Ctrl+u = underline
then going deep you can meet custom shortcut like i like to set: (Tools, Costumize, Keyboard)
ctr+w = increase fontsize,
ctrl+s = lower fontsize
ctrl+shift+w = uppercase
ctrl+shift+s = lowercare
however i'm looking for more... i'm thinking about tagging before word. Example: @substrate !enzyme §substrate in the end find and format the whole word after my tag in the way i want.

Probably my research should move on addons, anyway i trust forums and here's my point.

Every tip is very appreciated,
regards,
Stef
Last edited by StefArma on Sat Feb 25, 2017 7:35 pm, edited 1 time in total.
Open office 4.1.3 - Win7 Pro 64 bit
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Taking note and tagging format

Post by Zizi64 »

Using the direct (manual) formatting feature is not an effective method for text editing. Use the Styles instead of the direct formatting.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Hagar Delest
Moderator
Posts: 32627
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Taking note and tagging format

Post by Hagar Delest »

I think that the best method is to use the regular expressions (regex). The process would be:
- Write your text with your own tags (to be checked with the regex possibilities but you may have to start and end the string with the tag, the start only might not be enough to select the correct string).
- Afterward, use the Search & Replace feature to select your strings and apply the desired formatting. You can use character styles for that, you'll see that it's indeed a powerful feature to reformat your whole document at once.

You can have a list of the regex in your document to just copy-paste them in the dialog. However, for your use, I think it's definitively worth learning a little about macros. I use such kind of macro myself that search and replace for strings to be changed. With a single keystroke to launch the macro, once all the search and replace strings list are set, the changes will be done automatically at once. Quite time saving.

Don't hesitate to have a look at the macro forum, there are plenty of code snippets you could use.

Please add [Solved] at the beginning of the title in your first post (top of the topic) with the edit button if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
Hagar Delest
Moderator
Posts: 32627
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Taking note and tagging format

Post by Hagar Delest »

Here is a proposal. I let you discover the code and adapt it. Nothing very complicated.
You need to tag strings with a start and end tag like: here is the @string to be formatted@ in the text.
You have to code the formatting of your character styles. But if existing, it is not changed. So you can create a template with the existing styles already defined by the standard AOO interface.
I've used the method that apply the formatting with a FindAll routine because it does not work with the ReplaceAttributes routine. There may be a bug with the application of the character style (works fine for other attributes like font weight, ...).

You can add tags. You've to add them in the search variable and add a Case in the select case routine.

You have to call the macro with the menu Tools>Macros>Organize Macros>OpenOffice Basic and then Run Tag_My_Notes

Code: Select all

Sub Tag_My_Notes
Dim sSearchTag(5) as String 	' Number of tags
Dim sReplaceTag(5) as String	' Number of tags
Dim n, i as long
Dim oDoc, oReplace, oStyleChar, oCharStyles as object
Dim sCharStyle as string
oDoc = ThisComponent

' Declare here your Character styles
' Created if not existing
' If existing, the style is not modified
oCharStyles = oDoc.styleFamilies.getByName("CharacterStyles")

sCharStyle = ".substrate"
If Not oCharStyles.hasByName(sCharStyle) Then
	oCharStyles.insertByName(sCharStyle, oDoc.createInstance("com.sun.star.style.CharacterStyle"))
	oStyleChar = thisComponent.StyleFamilies.getByName("CharacterStyles").getByName(sCharStyle)
	oStyleChar.CharColor = RGB(255, 0, 0)
	oStyleChar.CharUnderline = 1
	oStyleChar.CharWeight = 100
	oStyleChar.CharBackColor = RGB(200, 200, 200)
End If

sCharStyle = ".enzyme"
If Not oCharStyles.hasByName(sCharStyle) Then
	oCharStyles.insertByName(sCharStyle, oDoc.createInstance("com.sun.star.style.CharacterStyle"))
	oStyleChar = thisComponent.StyleFamilies.getByName("CharacterStyles").getByName(sCharStyle)
	oStyleChar.CharColor = RGB(0, 0, 255)
	oStyleChar.CharWeight = 150
End If

sCharStyle = ".product"
If Not oCharStyles.hasByName(sCharStyle) Then
	oCharStyles.insertByName(sCharStyle, oDoc.createInstance("com.sun.star.style.CharacterStyle"))
	oStyleChar = thisComponent.StyleFamilies.getByName("CharacterStyles").getByName(sCharStyle)
	oStyleChar.CharColor = RGB(0, 255, 0)
End If

' Find the tagged strings & replace by the content (remove the tags)
sSearchTag() = Array("@([^@]*)@", "!([^!]*)!", "§([^§]*)§")
sReplaceTag() = Array("$1", "$1", "$1") ' As many "$1" as tags to be replaced
oReplace = ThisComponent.createReplaceDescriptor()
oReplace.SearchRegularExpression = True
For n = LBound(sSearchTag()) To UBound(sSearchTag())
	oReplace.SearchString = sSearchTag(n)
	' Find all the hits and change their character styles
	sTarget = ThisComponent.findAll(oReplace)
	For i = 0 To sTarget.count-1
		sFoundText = sTarget.getByIndex(i)
		Select Case sSearchTag(n)
		Case "@([^@]*)@":
			sCharName = ".substrate"
		Case "!([^!]*)!":
			sCharName = ".enzyme"
		Case "§([^§]*)§":
			sCharName = ".product"
		End Select
		sFoundText.CharStyleName = sCharName
	Next i
	' Replace the hits by removing the tags
	oReplace.ReplaceString = sReplaceTag(n)
	ThisComponent.ReplaceAll(oReplace)
Next n
End Sub
Please add [Solved] at the beginning of the title in your first post (top of the topic) with the edit button if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
StefArma
Posts: 2
Joined: Wed Feb 22, 2017 10:24 pm

Re: [Solved] Taking note and tagging format

Post by StefArma »

Wow thanks a lot! This is a very nice template and i can edit cases to adapt it to each of my works!
Open office 4.1.3 - Win7 Pro 64 bit
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Taking note and tagging format

Post by Villeroy »

If your text is written in Markdown, all you need to do is opening it with a Markdown editor and export as Open Document Text (odt).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply