more on punctuation, notes

More from John, first with his question, and then eventual resolution
(in VBA code I presume; BTW, anybody notice MS is dropping VBA from
future Mac versions of Office??):

In working on the Zotero Word plug-in, I see an issue that is, I think,
outside CSL, but about which you might have some wisdom.

The issue is punctuation and spacing around citations when switching
styles.
For example, an in-line citation at the end of a sentence should have a
space before the opening parenthesis, a period after the closing
parenthesis. If a note style is selected, the period should come before
the
reference mark and no space should precede the period. There are other
examples involving different punctuation.

One part of the solution is separating the responsibilities of the
user, of
the format specification, and of the processor. I assume the
specification
should be neutral on such issues. I also assume you’d like the user not
to
have to worry about it, that is, you’d rather the user not need to worry
about whether he does or doesn’t include a space before the citation.
That
would all mean the processor needs some rules for juggling the spacing
and
punctuation around citations. Is that right?

If so, have you by chance developed a set of such rules? If so, would
you
share them with me? Either way, could I get from you any thoughts on the
matter?===

I then suggested as a strawman these sorts of rules:

For note-based citations, preceding spaces should be removed. If the
citation comes at the end of a sentence, the note mark should be moved
outside the end-of-sentence period. If switching from note to in-text
styles, a preceding space should be added to the citation, and
end-of-sentence citations should be moved inside the period.

===

John’s result:

If isNote Then
’ convert to note-based
fField.Select
’ remove preceding space if one is there
If Selection.Start > 0 Then
selectstart = Selection.Start
Set a = ActiveDocument.Range(Start:=Selection.Range.Start - 1,
End:=Selection.Range.Start)
If a.text = " " Then
a.text = ""
End If
’ move following punctuation mark, if one is there, to before
the
citation field
’ and within any quotation marks if . or ,
fField.Select
Set b = ActiveDocument.Range(Start:=Selection.End,
End:=Selection.End + 1)
If b.text = “.” Or b.text = “;” Or b.text = “:” Or b.text = “,“
Or
b.text = “?” Or b.text = “!” Then
insideQuotationMarks = (b.text = “.” Or b.text = “,”)
punc = b.text
b.Cut
Set a = ActiveDocument.Range(Start:=Selection.Start - 1,
End:=Selection.Start)
If insideQuotationMarks Then
Do While a.text = " " Or a.text = “’” Or a.text =
Chr(34) Or
a.text = Chr(148) Or a.text = Chr(146)
a.SetRange Start:=a.Start - 1, End:=a.End - 1
Loop
End If
a.InsertAfter punc
End If
End If
Else
’ convert from note-based
fField.Select
’ move preceding . , ; : ? ! if one is there, to after the citation
field
’ for . , look even inside quotation marks
If Selection.Start > 0 Then
Set a = ActiveDocument.Range(Start:=Selection.Start - 1,
End:=Selection.Start)
If a.text = “.” Or a.text = “;” Or a = “:” Or a = “,” Or a =
”?” Or
a = “!” Then
punc = a.text
a.text = ""
Set b = ActiveDocument.Range(Start:=Selection.End,
End:=Selection.End)
b.InsertAfter (punc)
Else
’ move left until character is not either ’ " or right curly
versions of same
Do While a.text = “’” Or a.text = Chr(34) Or a.text =
Chr(148)
Or a.text = Chr(146)
a.SetRange Start:=a.Start - 1, End:=a.End - 1
Loop
If a.text = “.” Or a.text = “,” Then
punc = a.text
a.text = "“
Set b = ActiveDocument.Range(Start:=Selection.End,
End:=Selection.End)
b.InsertAfter (punc)
End If
End If
End If
’ add a preceding space unless there is a break (page/section,
paragraph
or column) there already
If Selection.Start > 0 Then
Set a = ActiveDocument.Range(Start:=Selection.Start - 1,
End:=Selection.Start)
If a.text <> " " And a.text <> vbCr And a.text <> Asc(12) And
a.text
<> Asc(14) Then
Selection.InsertBefore (” ")
End If
End If
End if