how to get parentheses to change to brackets when citation is in parentheses?

When I cite something within parentheses, I need the parentheses to (automatically) change to brackets. For example,
Prayer : A Critical Anthology, ed. Mark Kiley (London: Routledge, 1997)
within parentheses needs to look like this:
(See Prayer from Alexander to Constantine: A Critical Anthology, ed. Mark Christopher Kiley [London: Routledge, 1997])
How do I do this?

Miryam
«13
  • That punctuation is probably part of the style that you've selected. The CSL file would need to be modified.
    http://www.zotero.org/support/dev/creating_citation_styles
  • edited June 3, 2009
    Miryam,

    I assume that the parens are either in the text (written with the word processor, outside of Zotero) or in the prefix/suffix fields to a Zotero cite. In the former case, this behavior would be extremely difficult to support, and almost certainly never will be. In the latter case, it would at least be possible in principle, in the medium to long term. It's not a quick or simple item, though, unfortunately.

    It's a bit technical, but two steps would be needed to implement this. Currently, the parens (or brackets) around the publisher + year string in your example are hard-coded as literal text strings into the CSL style file that defines the formatting. There really isn't any way to alter those strings (apart from editing the citation after it has been generated by Zotero). However (this would be step one), there is movement toward introducing "flip-flop" formatting into CSL. This will make it possible, for example, for an (italicized) title inside another (italicized) title to appear in roman typeface. That is a very similar case to yours, at least at the foundation. However (this would be step two), applying "flip-flop" functionality to parens would require that, in the CSL files that define citation styles, they be cast not as simple text strings (as they are at present) but as formatting attributes (like "italic", "bold", or "superscript") -- and that would require changes to all of the (hundreds of) CSL styles used by Zotero. It's not impossible to do, but it would be a pretty sweeping change, and wouldn't be introduced lightly, I think.

    If you're very keen to see this functionality implemented eventually, it would help the case for adoption to establish that it is a general need. Can you provide a pointer to a style manual or a set of guidelines to authors that requires it?
  • edited June 5, 2009
    I assume that the parens are either in the text (written with the word processor, outside of Zotero) or in the prefix/suffix fields to a Zotero cite. In the former case, this behavior would be extremely difficult to support, and almost certainly never will be.
    Although I agree that this case would probably be very difficult to support in Zotero I would have thought it would be possible to do something with search and replace strings and regular expressions within the word processor. I'm not well acquainted with regular expressions so I'm not sure i'm up to it without a fair bit of reading around (I may try it at some point as a learning exercise - I'm afraid I can't commit to a timescale though).

    Miryam - If you are reasonably tech savvy it should probably be possible to do a couple of hours reading on regular expressions and macros (unless you are already familiar) in the documentation for either Word or OpenOffice and write or record a macro that replaces all the "nested" parens with brackets on a single mouse click after finishing a document. I can't guarantee this is possible, and I haven't thought through the logic, but it seems like something regular expressions should be able to manage.

    Something very vaguely related has been done at this thread.

    Edit: Things would become a bit more tricky if you had other "nested" parens in the document that needed to be treated differently to nested references.
  • Thanks for all your help! I'll try the macro solution, since the "nested parentheses" rule holds true throughout.

    I'll also look for a style guide that points to this, although I was a bit surprised to find that no-one else in the forums had this problem. It's considered basic in my field, and I assumed it was so for all of humanities.

    Thanks again,
    Miryam
  • P.S. Looking at it again you could probably do this with normal wildcards, which are simpler than regular expressions. A very useful guide (mentioned on the thread referenced above) can be found at

    http://word.mvps.org/FAQs/General/UsingWildcards.htm
  • "The Chicago Manual of Style" 15th edition (2003), p. 266 has:

    "6.102 Parentheses within parentheses. Athough the use of parentheses within parentheses (usually for bibliographic purposes) is permitted in some publications -- especially in law -- Chicago prefers brackets within parentheses (see 6.106)."...

    and p. 268:

    [under section "Brackets, Square Brackets"]:

    "6.106. Within Parentheses. Square brackets are used as parentheses within parentheses, usually for bibliographic purposes."...
  • jhy001,

    Thanks for this reference, I see this should be bumped up the priority list. In-field markup with flip-flop functionality is on the todo list for the new Zotero CSL citation formatter. We will already need support for quotes, and mixing in parens should not be too much extra trouble. It will take awhile, but support in the formatter will arrive in due course.
  • Can we start from the beginning and ask: why are you putting a complete (note?) citation in parenthesis to begin with? In my experience, those kinds of citations are typically sans parens.

    I have to say, I'm really uncomfortable with adding this sort of feature; seems at first glance another case of marginal value and unnecessary complexity.
  • Can we start from the beginning and ask: why are you putting a complete (note?) citation in parenthesis to begin with? In my experience, those kinds of citations are typically sans parens.
    Not to be stubborn or anything, but the users posting to the thread have backed this request up with specific references to the CMS, indicating that flipping to brackets is used "usually for bibliographic purposes". It may be perfectly reasonable to exclude support from CSL on benefit/burden grounds, but I think we have to accept that the use case has been proven.
  • edited July 29, 2009
    Not to be stubborn or anything, but the users posting to the thread have backed this request up with specific references to the CMS, indicating that flipping to brackets is used "usually for bibliographic purposes"
    The use case at this point is way too vague, since they haven't explained how these outer parenthesis happen. The excerpts they've quoted from Chicago don't really illuminate this issue.

    If, as I can only guess, the user has placed a citation within parentheses that are part of the document, then I consider that by definition out of scope for CSL.

    If OTOH the parentheses are part of the style definition, then the brackets can and should be defined in the style; e.g. no changes needed.

    In either case, from my reading, this isn't an issue for either CSL or a CSL processor.

    Or am I just missing something (perfectly possible)?
  • edited July 30, 2009
    Parens in the main document text are out of bounds obviously, but for parens in the user-supplied cite prefix and cite suffix fields, this is trivial to implement -- it can be addressed in citeproc-js with two lines of configuration code. It has no impact on the CSL schema, so I'll just go ahead and include the functionality in the new CSL processor. It will not work correctly for Chinese and Japanese unless there is locale support for the parens characters, but we can cross that bridge when we come to it.
  • But again:
    ... for parens in the user-supplied cite prefix and cite suffix fields
    Where is this a practical issue? I don't see the people in this thread asking for this, and the prefix and suffix fields on a citation are for simple text content (in the case at the top, the string "See ").
  • Less work to implement than to discuss, sorry.
  • Just a quick note to report that I've pushed the jalopy up the hill a couple of times, and concluded that Bruce is right; there doesn't seem to be a smooth or sensible way to automate this, at least at present.
  • Sorry to be late to this party, but I was doing a search on the parenthesis issue and found this thread. There seem to be three different issues being discussed here:

    1. Style guidance. "jhy001" has quoted the Chicago Manual of Style as a good source for flip-flopping between parentheses and square brackets when dealing with multiple levels of parentheses. This has been my personal practice and has been used by professional typesetters that I have worked with. I see it as similar to flip-flopping between single and double quotation marks.

    2. Need. I regularly find that I have multiple levels of parentheses in footnotes. In particular, one professional typesetter I used on a book project preferred a style like this in explanatory footnotes: "This metaphor reflects what von Rad (Deuteronomy: A Commentary [Old Testament Library; London: SCM, 1966], 197) terms the 'tradition of the finding' more than the exodus..." While multiple levels of parentheses can be avoided, sometimes it creates more confusion than it saves.

    3. Technical difficulty. I'm not sure what was decided here, whether trivial or impossible, but I implemented this feature in my own bibliographic system. I could share the code if anyone is interested, but it basically searched the MSWord text leading up to the particular citation field to see what sort of parenthesis/bracket came before the field, stopping at a hard line-break. Not overwhelmingly robust, but authors of malformed texts take their own chances!

    If this issue has been resolved elsewhere, my apologies, but thought I'd chime in.

    Thanks, as always, for a great project!

    --Rob
  • edited November 21, 2009
    Rob,

    Your example is new to us, I think. Is there a style guide that gives fuller treatment of the range of citation forms into which this example fits?

    PS: Re CMS, the general rule that flip-flopping should be performed applies to the document text as a whole, as I understand it. The citation formatter only knows about its own local context, as far as the textual context goes. Passing a hint from the plugin about parens nesting level would indeed be technically difficult, and may not be worth the cost in maintenance time and reliability/stability that would likely come with it, at least at present.
  • Again, I can echo the request for such functionality. I run into this frequently in explanatory notes.

    I'm wondering if a simpler solution would be to add a toggle box, like the "Suppress Author" box, that turns parenthesis into brackets. Of course, this wouldn't be as nice as something automatic, but I assume it would be much easier to implement. And it would do the job.
  • edited January 11, 2010
    rschellenberg: Can you provide another example of a full footnote that illustrates the desired behavior? The sticking point in the discussion is whether the parens are entered as part of the citation, or are in the word processor text. I'm curious about that point.

    (Probably a user option to toggle citation parens to braces is the best that can be done for this, though. If we try to do it automagically in the processor, it will sometimes work, sometimes not, depending on whether the enclosing parens are inside or outside of the citation controlled by the processor. That would probably cause more consternation than not.)
  • Sure. So as to demonstrate that the need for this is not merely due to an idiosyncrasy of mbrand and I, this is from someone else's work, in a 2003 book published by Trinity Press International.

    52. Assuming 3 m. between rows (Varro, De Agricultura 1.8.5) and between 1.0 and 1.83 m. between plants (Carey Walsh, The Fruit of the Vine: Viticulture in Ancient Israel and the Hebrew Bible [Winona Lake, Ind., Eisenbrauns, 2000], 110), one hectare would hold between 1650 and 3333.5 vines.

    When I do this sort of thing, I enter the outer parentheses in Word, then change the inner parentheses generated by Zotero to brackets using the citation editor. That works, but it's tedious, and it "freezes" the citation: If the author of n. 52 above had used that method, then decided to cite Walsh's book in n. 12, the citation above would not have adjusted to "short title" format.

    Does that clarify?
  • @rschellenberg
    yeah - that's the issue that Frank describes as almost impossible to solve (and while a "flip parentheses" button is an option it would be a button for a tiny fraction of users, so I'm not sure that's a great idea).
    If you entered all of this as one single Zotero citation, using the suffix and prefix fields, that is more likely to be feasible.
  • edited January 11, 2010
    I see. The parens in this case enclose the citation. If this is a property of citations, it's doable, but I wonder ... in this style, if citations are always enclosed in parens, won't the publisher + year string always be enclosed in braces? On the face of it, it looks like that would be the case.
  • Frank - no it won't - note that this is only when there is a citation that's part of a larger explanatory note - a simple verbatim citation from the same book would be:

    11. Carey Walsh, The Fruit of the Vine: Viticulture in Ancient Israel and the Hebrew Bible (Winona Lake, Ind., Eisenbrauns, 2000), 110.
  • Ah, okay. There's a user interface issue here, then. The prefix/suffix fields on a cite apply to a specific reference, and don't capture the entire citation when there are multiple cites. It's really a UI design decision for Zotero in the first instance, whether to provide additional options or fields to decorate the citation as a whole. The added complexity might be confusing to people who don't require it. Tough one.
  • I don't really see a solution without a button. (Although I admit it's peculiar to me that more people don't have this issue.)

    Rob, could you share your "search" solution?
  • @mbrand: happy to oblige.

    I paste in the full code below (in a Java-ized form of MSWord VBA). But the basic idea is that I do two searches that begin from the citation that I'm trying to format.

    The first search begins from the left side of the citation and searches backward through the text, looking for either a paren or a paragraph break.

    The second search looks from the right side of the citation and searches forward through the text, looking for the same things.

    If the first search finds a '(' and the second search finds a ')', then it concludes the citation is within parentheses and then swaps all of the parenthesis and bracket characters within the citation.

    In my experience, this has accomplished the automatic formatting that I need. Comments welcome.

    Thanks for your interest!
    --Rob

    ------------------------

    protected boolean _selectionIsInParens() {
    boolean inParens = false;
    Range currentSelectionRange = app.getSelection().getRange();
    java.lang.System.out.println("Selected text: "+currentSelectionRange.getText());
    // collapse to the starting point
    _collapseSelectionToStart();
    Find find = app.getSelection().getFind();
    // find previous parentheses [either a '(' or a ')' or a paragraph break]
    find.setText("[\\(\\)^13]");
    find.getReplacement().setText("");
    find.setForward(false);
    find.setWrap(WdFindWrap.wdFindStop);
    find.setFormat(false);
    find.setMatchCase(false);
    find.setMatchWholeWord(false);
    find.setMatchAllWordForms(false);
    find.setMatchSoundsLike(false);
    find.setMatchWildcards(true);
    boolean foundLeft = find.execute();
    if (foundLeft) java.lang.System.out.println(" found left: '"+app.getSelection().getText()+"'");
    // restore selection
    // did we find an open paren first?
    if (foundLeft && "(".equals(app.getSelection().getText())) {
    // collapse to the end point of the selection
    app.getSelection().setRange( currentSelectionRange.getStart(), currentSelectionRange.getEnd() );
    _collapseSelectionToEnd();
    find = app.getSelection().getFind();
    // find following parentheses [either a '(' or a ')' or a paragraph break]
    find.setText("[\\(\\)^13]");
    find.getReplacement().setText("");
    find.setForward(true);
    find.setWrap(WdFindWrap.wdFindStop);
    find.setFormat(false);
    find.setMatchCase(false);
    find.setMatchWholeWord(false);
    find.setMatchAllWordForms(false);
    find.setMatchSoundsLike(false);
    find.setMatchWildcards(true);
    boolean foundRight = find.execute();
    if (foundRight) java.lang.System.out.println(" found right: '"+app.getSelection().getText()+"'");
    // did we find a close paren first?
    if (foundRight && ")".equals(app.getSelection().getText())) {
    inParens = true;
    }
    }
    // restore selection
    app.getSelection().setRange( currentSelectionRange.getStart(), currentSelectionRange.getEnd() );
    // if we have an open before us and a close after us, we are in parens
    return inParens;
    }
  • Is there a way I can run this in standard MSWord VBA? My Word won't let me run it as is in a macro. Thanks!
  • I took a few minutes to change this into a straight VBA Macro (apologies for being a terrible VBA hack...) that at least shows the basic idea.

    Here's a macro that detects whether the selection lies within parentheses (and thus requires swapping of parens and brackets within the selection) and pops up a message box about what it found.

    If it's helpful, I uploaded a Word document with the macro already in it that you can play with. It's available at: http://coffeewithbarretts.com/uploads/SearchParens.docm

    Sub isInParens()
    Dim foundTextLeft As String
    Dim foundTextRight As String
    Dim citationRange As Range
    Dim inParens As Boolean

    inParens = False
    foundTextLeft = "not-searched"
    foundTextRight = "not-searched"

    rangeStart = Selection.Range.Start
    rangeEnd = Selection.Range.End
    Selection.Collapse (wdCollapseStart)

    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "[\(\)^13]"
    .Replacement.Text = ""
    .Forward = False
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchKashida = False
    .MatchDiacritics = False
    .MatchAlefHamza = False
    .MatchControl = False
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    If Selection.Find.Execute Then
    foundTextLeft = Selection
    If foundTextLeft = "(" Then
    Selection.SetRange Start:=rangeStart, End:=rangeEnd
    Selection.Collapse (wdCollapseEnd)
    MsgBox ("selection reset")
    With Selection.Find
    .Text = "[\(\)^13]"
    .Forward = True
    End With
    If Selection.Find.Execute Then
    foundTextRight = Selection
    If foundTextRight = ")" Then
    inParens = True
    End If
    End If
    End If
    End If
    Selection.SetRange Start:=rangeStart, End:=rangeEnd

    MsgBox ("LeftText=" & foundTextLeft _
    & " RightText=" & foundTextRight _
    & " inParens = " & inParens)
    End Sub
  • Hi, I have a related (maybe easier) problem. I often cite within parentheses:

    (see Ackerman, 2009); (e.g., Ackerman, 2009)

    but the citation populates as:

    (see (Ackerman, 2009)

    Which is incorrect. Any ideas on how this can be fixed?

    Thanks!
  • use the prefix (and suffix) field in the plugin for things like see, c.f. e.g.
  • Rob, I've been playing around with your macro and can't seem to get it to work. (The fact that I'm clueless as far as VBA goes can't help). Anyway, the link to your paper that has the macro in it isn't working. Could you make that available again?

    Thanks, Ryan
Sign In or Register to comment.