Archive | writing RSS for this section

Manipulate multiple selections in Word — GUI and macro

Note to self: Well, it’s not flexible, but it’s useful. Styling documents in Word — that is, making sure they are rigorously styled rather than formatted in an ad hoc way — is a pain.

I wanted to search for a specific bit of text and format it in a specific way. Problem; something was embedded in the Word doc such that highlighting the text and selecting the style did not work; I had to select ‘Clear All’ in the styles pane before I could apply the style I wanted.

 

Now, can you make multiple selections via the Search tool and then process them all at once? Yes.

(1) Ctrl-H to open search tool, and just select find. Here I am going to convert all ‘the’ to Heading 3.

(2) Type ‘the’ in ‘Find what:’ and under ‘Find in’ select ‘Main Document’ (this is the core of the trick — for whatever reason).

(3) When you click on ‘Main Document’ you’ll get a message telling you how many instances were found and they’ll be highlighted on the screen.

(4) Press ‘Esc’.

(5) You can now operate on all the selections at once. In this case, I’ve converted them all to Heading 3 styles, but it could be anything else you like.

Here is a macro that will do the same:

Sub TestSearch()
'
' TestSearch Macro
' Search for some text and process it when it is found, repeat untill all instances done.
'
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "the"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    While Selection.Find.Found
        Selection.ClearFormatting
        Selection.Style = ActiveDocument.Styles("Heading 3 Char")
    Selection.Find.Execute
Wend
End Sub

 

FWIW

Advertisements

Guinness World Record attempt at the most authors contributing to an anthology of short stories

Well, here it is, what the world’s been crying out for… a great big book of brand new stories, so many in fact that a world record is in sight if enough copies get sold. The details are at  https://celenicearthpublications.wordpress.com/anthologies/cea-greatest-anthology-written/.

The writers are from all over the world and all sorts of genres. The Smashwords link is here.

The cover:

Cover of the Greatest Anthology Written

The cover of one big book.

 

Big stuff.

Weird Word behaviour part N+1

Styles in tables act funny. Here is a table (with the few codes that Word lets me see visible):

The bottom of the third data row shows an empty line that I don’t want. Here is what happens when I delete that line:

Huh! The line gets changed to a different size and the bullet point goes away —  and I cannot get it back! I cannot insert a bullet using the bullet menu on the toolbar/ribbon/whatever it’s called this week, but I can insert one using shortcut key combination (Ctrl+Shift+L). But the formatting is wrong — and when I make it right, the bullet goes away!

But that is a hint — the problem probably lies in an interaction between some aspect of the style the document specifies for bullets in tables and Word’s bulleting code. So, what I did was copy the second (working) bullet point, so the list had two bullet points the same. Then I cut the text of the third point (the one I wanted) and pasted it into a brand new document as plain text. I deleted everything that was not text that I wanted, then pasted that back into the third bullet point in the table,  as plain text (which means it takes the formatting around it) so I had a third bullet that looked like:

  • theirspending on furniture broken down by number of legs and fabric typecosts

Then I was able to delete the unwanted line, then delete ‘their’ and ‘costs’ to leave what I wanted. It’s all about getting rid of Word’s hidden codes that don’t do what they should. Now I’ve got:

which is what I wanted.

Random useful Word stuff

Notes to self.

(http://www.fileformat.info/info/unicode/category/Sm/list.htm)

(‘␣’ means empty space, eg one hit of the space bar; ‘Alt-x’ means hold down ‘Alt’ and press ‘x’. If a space is not marked with the empty space character, it is just used to separate commands and should not be typed.)

in Word, type ␣2212 Alt-x to get a proper minus sign, not an en rule or a hyphen; it sits at the right height and gives the right spacing. The space in front is not always needed, but may be needed to separate the ‘2212’ from the previous characters so Word knows what to apply the ‘Alt-x’ function to. Here are the other ones I find most useful:

Useful Alt-x codes for maths in Word

If in the ‘Advanced find’ dialogue I select ‘Use wildcards’ then the search differentiates between non-breaking spaces and spaces.

Just some stuff.

Other stuff.

 

 

 

 

Search insde Word, PDF, XML and other files—installing and using crgrep

I am an editor in a business that uses Micro$oft products, but I want to be able to use the Linux CLI tools with which I am moderately familiar. In particular, I want to be able to grep Word documents, and that’s a problem because the new Word file format chops the text up and zips it up and hides it away. I googled and read a bit about crgrep (‘common resource grep’). Here is my experience so far.

Downloaded from

https://bitbucket.org/cryanfuse/crgrep

or

https://sourceforge.net/projects/crgrep/

Created a subdirectory c:\Users\username\installs\crgrep and downloaded the zip file into it. Worked in Cygwin, hence the forward slashes and dollar signs in the following. This could also be done through the GUI or in a PowerShell or CMD window. Choice is a wonderful thing.

$ unzip crgrep-1.0.5.zip
$ cd crgrep-1.0.5/
$ vim INSTALL.txt

OK, so it needs java. Does it need the compiler (probably not, but check…). In the crgrep folder, typed:

$ grep -ir javac

Returned no results calling the javac compiler. So it looks like the program needs the runtime but not the development kit (JDK), so that’s good. It’s what you’d expect. Now, I have the wonderful ImageJ installed (works effortlessly in userspace), and it installs the Java runtime environment, JRE. Maybe I can use that.

Now, according to the INSTALL.txt file, the JAVA_HOME variable that crgrep wants points at something like

JAVA_HOME=C:\Program Files\Java\jdk1.8.0_xx

and my grepping told me that java.exe should be in %JAVA_HOME%\bin\java.exe

In Cygwin, my ImageJ tree looks like:

/cygdrive/c/Users/username/installs/ij/ImageJ/jre/bin

Which meant I needed to set JAVA_HOME to be C:\Users\username\installs\ij\ImageJ\jre (Windows-style path) (that is, the variable points the directory with the bin directory inside it, not the bin directory or the binary file itself.)

But first checked the version — needs 1.8.

$ cd ../../ij/ImageJ/jre/bin/

$ ./java.exe -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

OK.

I installed in userspace (work computer, no root/admin access), so I went to my Windows account settings (given the various versions of Windows, I’ll assume a user can find their own account setting page) and (for Win 10; Win 7 is no doubt different) in the ‘Find a Setting’ box I typed ‘env’ for ‘environment variables’, and chose ‘edit the variables for your account’. Note that searching for ‘path’ turns up nothing. It’s a little trick!

Added an entry to the path:

(Path → Edit → New)

c:\Users\username\installs\crgrep\crgrep-1.0.5\bin

and created a new environment variable:

JAVA_HOME=C:\Users\username\installs\ij\ImageJ\jre

And exited everything, esp. the command line window, then opened it again, typed SET in a CMD (‘DOS’) window to see if the new variables were present, then tried the command:

H:>crgrep --help
usage: crgrep [options]  []
crgrep: Common Resource Grep.
 -a,--text               Process binary files or database columns as if
                         they were text
    --color        Alias for 'colour'.
    --colour       Colour-highlight matched text ('always', 'auto'
                         or 'never'). Default colour is red, see USAGE.txt
                         for other colour settings.
 -d,--database           Database grep (disables file search)
 -h,--help               Help
 -i,--ignore-case        Ignore case distinctions in matched text
 -l,--list               List resources which produce a match by name. No
                         content is searched.
 -m,--maven              Include Maven POM file dependencies in search
    --mood    Only include matching content expressing a
                         specific sentiment; values include 'positive',
                         'negative' or 'neutral'. Ignored if -l specified.
                         Requires model data; see INSTALL.txt
    --ocr                Enable OCR text extraction from images; requires
                         tesseract libraries. See INSTALL.txt
 -p,--password      Password required to access a resource,
                         optionally used with -u
 -P,--proxy         Proxy settings for http access, specified as
                         [:]
 -r,--recurse            Recursive search into resources
 -u,--user          User ID or username required to access a resource
 -U,--uri           URI to specify a JDBC database resource
 -V,--version            Print the version number of CRGREP to the
                         standard output stream
    --warn               Display all warnings to standard output
 -X,--extensions    Enable one or more extensions; comma sep. list
                         such as -Xdebug,trace
If  is not specified, or is '-', read from stdin
Please report issues at https://bitbucket.org/cryanfuse/crgrep/issues

OK, promising.

I want it for grepping Word files, so let’s see… yes, it finds ‘data’ in the test file, and outputs a nice clean stream:

H:>crgrep data text.docx
text.docx:T:A key part of his research was the analysis of large
datasets. As part of this he developed a software suite that included
data modelling, reduction and correction techniques, and made of use the
National Computing Infrastructure and other supercomputers. He enjoys
the challenge of analysing and explaining complex data using words and
carefully designed graphics. He likes Linux and the LATEXtypesetting
system.

How about PDF? Converted the Word doc to PDF using the ‘Save as’ dialogue in Word. Then…

H:\>crgrep data text.pdf
text.pdf:1:36:datasets. As part of this he developed a software suite
text.pdf:1:37:that included data modelling, reduction and correction
text.pdf:1:40:challenge of analysing and explaining complex data using

Different output because of how PDF and Word chop up the text, but instances found in both cases. No need to specify a file type or anything. I have not explored the command line options, but I am already finding the program useful — for example, when I want to find multiple instances of multiple expressions (say acronyms or references) in multifile projects.

Kudos.

Just grepping around.

CAPS LOCK disable on Windows without admin rights

Lots of sites tell you how to disable/remap CapsLock. But what if you don’t have administrator rights? Most of them tell you to pry off the key. Well, instead, I went to:

https://dropline.net/2009/05/mapping-caps-lock-to-control-without-admin-access/

Here is an extract, which I put here just in case the original site vanishes, as sites sometimes do:

There’s a duplicate of the keyboard mapping registry key under HKEY_CURRENT_USER, which non-administrators can modify, and it appears to behave exactly like the key under HKEY_LOCAL_MACHINE.  So, for anyone in a similar position, here’s the registry key to modify:

HKEY_CURRENT_USER→Keyboard Layout→Scancode Map =
hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00

You can download a registry update file here.  Save it to your computer, double-click it to update your registry, then reboot and enjoy your vastly-improved keyboard.

Here is a screengrab of the .reg file:

capslock

Worked a treat on Windows 7, but it did not work on Windows 10.

Hmm…Code for conversion of CapsLock to Shift is:

00,00,00,00,00,00,00,00,02,00,00,00,2a,00,3a,00,00,00,00,00

(http://johnhaller.com/useful-stuff/disable-caps-lock)

Codes explained here:

https://www.experts-exchange.com/articles/2155/Keyboard-Remapping-CAPSLOCK-to-Ctrl-and-Beyond.html

But why it does not work in Windows 10 I don’t know. I did try it on a work desktop machine (that’s why I don’t have admin rights, ‘cos it’s a work machine), so perhaps it downloads registry files on logging in? Does that make any sense?

Right now I don’t care enough to find out, but I’ll look into it at some point in the future.

 

So there.

Another Font for a Very Specific Purpose

I have been reading stuff on my HP200LX palmtop using VR, the Vertical Reader.  It basically turns the LX into a pretty useful book reader — ASCII only.  You have a single column of text, rather like a newspaper column. It’s most excellent. It comes with search, bookmark and various customisation facilities.

However, I found the fonts that came with it just a bit too small. I decided to make one of my own, which is at an old post here, but it went too far the other way and is too wide. So I decided to take that font and narrow it a bit — make a condensed version, in the correct parlance. Thus:

The two fonts are shown below. The comments about the design philosophy in the earlier post remain valid; but the new one is I think just as readable and gets quite a bit more text on the screen.

‘djgtry2.vfn’

Using the font 'djgthin.vfn'.

Using the font ‘djgthin.vfn’.

The new font is available at DSPACE, along with the earlier one. The file to download is DJGTHIN.VFN.zip.

For what it is worth.

Changing the language in Word comment boxes

M$ Word does have a lot of power. It’s very successfully buried. Here’s a thing: the proofing language for the text is set separately from that for any comments you add to the text. It is I suppose a good thing to have separate control over these types of content. The language for comments is determined by the template for the file and may not be what you want. The link below goes to a very useful explanation that shows how to set it to be what you want. I include it here because I found it so useful. I don’t often reblog.

Source: Changing the language in Word comment boxes

Wordy.

Non-breaking en rule (en dash) in Microsoft Word… not really.

Say you’ve got a number range. The proper way to format that is with an en rule (en dash), so it looks something like ‘4­–5’ whereas a hyphen would look like ‘4-5’. Now, you probably don’t want the number range to break across lines. That’s fine with a hyphen, since Ctrl-Shift-Hyphen gives a non-breaking hyphen (in Word). But you don’t want a hyphen you want an en rule. One option is to put in a non-breaking hyphen then make it twice as wide.

  • Highlight the non-breaking hyphen (and the hyphen alone, not any trailing/leading characters or spaces).
  • Right click on the hyphen and select the ‘Font…’ menu, then ‘Advanced’ (rule #1 in Microsoft products: Just about anything worth doing is considered ‘Advanced’).
  • Change the number in the ‘Scale’ box to be about 200%.
  • Exit from the menus.
  • Type an en rule in your document, alongside the stretched hyphen. (Ctrl-Keypad Minus.)
  • Compare.
  • Swear.
  • Use it anyway since it’s the most reasonable alternative. You may want to adjust the height; but will this highly manual fix work if font is then changed? No.
  • Watch while Word mysteriously moves the instruction to widen the characters to random places in the document so you end up with double width text in unexpected places.
  • Swear.
  • Learn LaTeX where all you need to type is \mbox{4–5}.
Dialog box in Microsoft Word for changing character size, position and spacing.

Stretch out the hyphen (or anything else) using the ‘Scale’ box. Gives fixed selections but can type in other values. Something between 175% and 225% usually works. Note: Can also be used to adjust the position if need be.

I have tried putting text in boxes, but the baseline is not maintained – it sits high. Character positions can be adjusted down, but then Word boxes clip the contents. Perhaps there is a better solution? I tried making it an equation, or using a minus character, but neither was really satisfactory. I’d like to hear about a better answer because, sadly, using LaTeX is not always viable.

Non-bresaking en rule in Word; results of stretching a hyphen.

Non-breaking en rule in Word; results of stretching a hyphen.

My Word.