Hello again Nobumi,

so here is a sample macro to do this. One of the most useful tricks here is the “$” option of NW find. In your case, you have footnotes that look like this:

1. xxxxxxx

You want to find both the number of the footnote “1.” and the text “xxxxxx” and then you will want to throw away the number and keep the text. This is a lot to do, but Nisus can do it all in one step:

Find '(?<fn_num>\d+)\. (?<fn_text>.+)', '$E

The “$” option lets Nisus name parts of the found text and give them names. Do this use the special parentheses:

(?<___> … )

In the angle brackets, you can put the name of the variable, and in the parentheses you put the find expression. This can only be done with single find, not “Find All”, obviously.

The overall macro is pretty simple. We start with two document objects $main_doc and $notes_doc. Then it looks like this:

# Get all the notes as well as the references in the main document
$note_Refs = $main_doc.text.find '\(\d+\)', 'Ea'
$notes = $notes_doc.text.find '^\d+\. .+', ‘Ea'

# Process each reference in the main doc from back to front
foreach $ref in reversed $note_Refs

    $fn_text = … (get the right footnote text from $notes) …
    Note.insertFootnoteInTextAtIndex $ref.text, $ref.location, $fn_text

end

The bit about getting the footnote text uses the find trick mentioned above.
And that’s really it. I’ve just added some checking to try to make sure everything checks out. The other point is how to get the two docs. I just assumed it’s the front two docs: $main in front $notes behind it. And finally you asked that this be done in a separate, new document. I didn’t do this. You could just copy the main document, and close it, or use some other set-up. I was too lazy for that ;-)

Hope this helps
Philip

################# Transfer notes to main document #######################

# Assumes the front two documents are the ones we want
$main_doc = Document.openDocuments[0]
$notes_doc = Document.openDocuments[1]

# Get all the notes as well as the references in the main document
$note_Refs = $main_doc.text.find '\(\d+\)', 'Ea'
$notes = $notes_doc.text.find '^\d+\. .+', 'Ea'

# Check the number of notes
if $note_Refs.count != $notes.count
    die 'The notes and references don\'t match'
end

# Process each reference in the main doc from back to front
foreach $ref in reversed $note_Refs

    # Get the number 
    $ref.substring.find '(?<num>\d+)', '$E'

    # If the number is too big, something is wrong
    if $num > $notes.count
        die 'Note number is too big'
    end

    # Get the matching note text and its number
    $note_with_num = $notes[$num - 1].subtext
    $note_with_num.find '(?<fn_num>\d+)\. (?<fn_text>.+)', '$E'

    # Check that the footnote number matches
    if $fn_num == $num
        # Remove the parentheses and reference number from the text
        $ref.text.deleteInRange $ref.range
        # Insert a footnote instead
        Note.insertFootnoteInTextAtIndex $ref.text, $ref.location, $fn_text
    else
        Prompt "I found a problem with note $num"
    end
end

################# end of macro #################

On 2016 Jul 14, at 08:15, Nobumi Iyanaga <[log in to unmask]> wrote:

Hello,

Here is the macro I would like to have -- that I tried to write myself, but this seems too difficult for me.

I have two documents, one containing the main text with footnote numbers in plain text (in the format "(x)"), and the other containing all the notes, each consisting in one line, beginning with "1. ", "2. ", etc.

In other words, the two files are like this:

main text document:

aaaaaaaaaa (1), bbbbbbbb (2) ccccccc (3)...

notes document:

1. xxxxxxxx
2. yyyyyyy
3. zzzzzzzz

etc.

The regex "\(\d+\)" finds all the note numbers in the main text, and nothing else; and the regex "^.+$" finds all the note contents.

I would like to make a new document in which the notes will be incorporated as footnotes. How can I do this?

Thank you very much in advance for your insight.

Best regard,

Nobumi Iyanaga
Tokyo,
Japan

Philip Spaelti