NISUS Archives

February 2011

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Sat, 26 Feb 2011 20:51:03 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (96 lines)
At the actual stage of my proof reading my own writing whose deadline is approaching very near, I felt the necessity to see it vertically typeset. To convert footnotes into in-line notes enclosed by LaTeX tags, I run my Note to Body macro on the file and it failed. Not having the time to investigate the issue, I hacked the macro in a hurry so that it does not rely any more on the locations of note references (in body) in the original document.
<http://www2.odn.ne.jp/alt-quinon/files/NWPro/footendnotes/Note2Body_20110226_nwm.zip>


I did not know this: 'TextSelection.newWithLocationAndLength $text, $i, 1' (at line 61) returns a TextSelectio objects whose length is *three* if the note reference at $i is '102', for example.


Kino

--

### Note2Body macro (rev 16) ###

# This macro will produce a new document where all footnotes and end/section notes will be converted into inline notes enclosed by tags such as \footnote{...}.

# The tags are customizable. Define $fnPrefix, $fnSuffix, $enPrefix and $enSuffix near the beigining of macro code as you like.

# Characters between Note References and Note Text will be removed if they are the same as Default Note Text defined in the Style Sheet.


Require Pro Version 1.3
Debug.setCodeProfilingEnabled false
Debug.setDestination 'none'
$prefix = $suffix = $defaultNT = $count = Hash.new

$prefix{'footnotes'} = Cast to String '\footnote{'
$suffix{'footnotes'} = Cast to String '}'
$prefix{'endnotes'} = Cast to String '\endnote{'
$suffix{'endnotes'} = Cast to String '}'

# $prefix{'footnotes'} = Cast to String '{{'
# $suffix{'footnotes'} = Cast to String '}}'
# $prefix{'endnotes'} = Cast to String '(('
# $suffix{'endnotes'} = Cast to String '))'

$doc = Document.active
$notes = $doc.allNotes  # get all note objects and put it in $notes (array)

if ! $notes.count
	exit 'No note found, exit...'
end

$startTime = Date.now
$text = $doc.text.copy  # get the main text object of $doc and put it in $text (variable)

$lenPrev = $text.length
$note = Note.insertFootnoteInTextAtIndex $text, $text.length
$defaultNT{'footnotes'} = $defaultNT{'endnotes'} = $defaultNT{'sectionnotes'} = '\A\Q'
$defaultNT{'footnotes'} &= $note.contentSubtext & '\E'
$note = Note.insertEndnoteInTextAtIndex $text, $text.length
$defaultNT{'endnotes'} = $defaultNT{'sectionnotes'} &= $note.contentSubtext  & '\E'
$delRange = Range.newWithLocationAndBound $lenPrev, $text.length
$text.deleteInRange $delRange

$error = ''
$placementToType = Hash.new 'page', 'footnotes', 'section', 'endnotes', 'document', 'endnotes'

$i = $text.length - 1
while $i
	$note = $text.noteAtIndex $i
	if Defined $note
		$type = $placementToType{$note.placement}
		$count{$type} += 1
		$content = $note.contentSubtext # get note text and put it in $content (variable)
		$replaced = $content.findAndReplace $defaultNT{$type}, '', 'E'  # remove Default Note Text from $content
		if $replaced == undefined
			$n = $i + 1
			$error = "Default Note Text for note $n ($type) could not be removed.\n" & $error
		end
		$content = $prefix{$type} & $content  # put $prefix corresponding with $type before $content
		$content &= $suffix{$type}  # append $suffix corresponding to $type to $content
		$sel = TextSelection.newWithLocationAndLength $text, $i, 1
		$text.replaceInRange $sel.range, $content  # replace the note reference in the body with $content
		$i = $sel.location
	end
	$i -= 1
end

Document.newWithText $text

$finishTime = Date.now
$seconds = $finishTime.secondsSinceUnixEpoch - $startTime.secondsSinceUnixEpoch
$message = "Finished in $seconds s:\n"

foreach $type in $count.keys
	$message &= "\n" & $count{$type}
	$message &= " $type"
end
if $error
	$message &= "\n" & $error
end

exit $message

### end of macro ###

ATOM RSS1 RSS2