public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //return handled = true if this macro generates the output (as an IEnumerable<ITextUnit>); the standard output will be suppressed //return handled = false if you want Citavi to produce the standard output; handled = false; var useNonBreakingSpacesInAndBetweenFirstAndMiddleNames = false; //if true, then e.g. Meyers, J.°R. var useNonBreakingSpaceBetweenLastAndFirstName = false; //if true, then e.g. Meyers,°John Richard var useNonBreakingSpaceBetweenPrefixAndName = false; //if true, then e.g. von°Bülow, V. var useNonBreakingHyphenInFirstAndMiddleName = false; //if true, then e.g. Ewing, J.-R. if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } #region ThisPersonFieldElement PersonFieldElement thisPersonFieldElement = GetFirstPersonFieldElement(componentPart); if (thisPersonFieldElement == null || thisPersonFieldElement.SuppressOutput) { return(null); } #endregion #region ThesePersons IEnumerable <Person> thesePersons = thisPersonFieldElement.GetPersons(citation); if (thesePersons == null || !thesePersons.Any()) { return(null); } #endregion #region PreviousPersonFieldElement PersonFieldElement previousPersonFieldElement = GetPreviousPersonFieldElement(thisPersonFieldElement, template, citation); if (previousPersonFieldElement == null) { return(null); } #endregion #region PreviousPersons IEnumerable <Person> previousPersons = previousPersonFieldElement.GetPersons(citation); if (previousPersons == null || !previousPersons.Any()) { return(null); } #endregion IEnumerable <PersonFieldElement> personFieldElements = componentPart.Elements.OfType <PersonFieldElement>(); if (personFieldElements == null || personFieldElements.Count() == 0) { return(null); } PersonTeamsCompareResult compareResult = GetPersonTeamsIdentityAndGenderStructure(thesePersons, previousPersons); if (compareResult.Identity == PersonTeamsIdentity.None) //return null; [old version without useNonBreakingSpace...] { foreach (PersonFieldElement element in personFieldElements) { if (useNonBreakingSpacesInAndBetweenFirstAndMiddleNames) { element.FirstGroupUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; element.SecondGroupUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; element.LastPersonUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; } if (useNonBreakingSpaceBetweenLastAndFirstName) { element.FirstGroupUseNonBreakingSpaceBetweenLastAndFirstName = true; element.SecondGroupUseNonBreakingSpaceBetweenLastAndFirstName = true; element.LastPersonUseNonBreakingSpaceBetweenLastAndFirstName = true; } if (useNonBreakingSpaceBetweenPrefixAndName) { element.FirstGroupUseNonBreakingSpaceBetweenPrefixAndName = true; element.SecondGroupUseNonBreakingSpaceBetweenPrefixAndName = true; element.LastPersonUseNonBreakingSpaceBetweenPrefixAndName = true; } if (useNonBreakingHyphenInFirstAndMiddleName) { element.FirstGroupUseNonBreakingHyphenInFirstAndMiddleNames = true; element.SecondGroupUseNonBreakingHyphenInFirstAndMiddleNames = true; element.LastPersonUseNonBreakingHyphenInFirstAndMiddleNames = true; } } //for downward compatibility of this script we make sure the separator is just a comma and not "comma + space" var currentVersion = SwissAcademic.Environment.InformationalVersion; var maxVersionForWorkaround = new Version(6, 3, 5, 0); if (currentVersion <= maxVersionForWorkaround) { foreach (PersonFieldElement element in personFieldElements) { element.FirstGroupLastNameFirstNameSeparator.Text = ","; element.SecondGroupLastNameFirstNameSeparator.Text = ","; element.LastPersonLastNameFirstNameSeparator.Text = ","; } } //Citavi will do the rest, no need to return any output, since PersonTeamsIdentity.None = true return(null); } bool handleAlsoPartialIdentity = true; //if true, all of the following cases (1) - (3) will be treated. Otherwise, //if false, only case (2) will be treated bool confineReplacementToSingleAuthorOnPartialIdentity = true; //ignored if handleAlsoPartialIdentity = false; //if true, only cases (1) and (2) will be treated //(1) Watson, Mary, »An interesting contribution«, in: eadem / Smith, Emma (Eds.), Edited book with 2 editors, London 2012. //(2) Watson, Mary / Smith, Emma, »An interesting contribution«, in: iidem (Eds.), Edited book with 2 editors, London 2012. //(3) Watson, Mary / Smith, Emma, »A rather boring contribution«, in: iidem / Green, Peter (Eds.), Edited book with 3 editors, London 2012. if (compareResult.Identity == PersonTeamsIdentity.Partial && !handleAlsoPartialIdentity) { return(null); } if (compareResult.Identity == PersonTeamsIdentity.Partial && previousPersons.Count() > 1 && confineReplacementToSingleAuthorOnPartialIdentity) { return(null); } //if you want "ders."/"dies." written in italics or other font styles, choose the desired option, for example FontStyle.Italic, FontStyle.Bold or FontStyle.SmallCaps LiteralTextUnit idemSingularMaleLiteral = new LiteralTextUnit("Ders.", FontStyle.Neutral); LiteralTextUnit idemSingularFemaleLiteral = new LiteralTextUnit("Dies.", FontStyle.Neutral); LiteralTextUnit idemSingularNeutralLiteral = new LiteralTextUnit("Dass.", FontStyle.Neutral); LiteralTextUnit idemPluralLiteral = new LiteralTextUnit("Dies.", FontStyle.Neutral); //NOTE: If you want a prefix such as "In: " and a suffix " (Hrsg.)", you can define them as group prefix and suffix on the field element inside the component part editor //CAUTION: This script will get more complex, if the separators between persons differ from group to group of for the last person LiteralTextUnit personSeparator = new LiteralTextUnit(thisPersonFieldElement.FirstGroupPersonSeparator.Text, thisPersonFieldElement.FirstGroupPersonSeparator.FontStyle); //we remove all separators, because some person names will have to be suppressed and we want to avoid excess separators such as the /'s in idem///John Smith thisPersonFieldElement.FirstGroupPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupLastPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupToSecondGroupSeparator.Text = ""; thisPersonFieldElement.SecondGroupPersonSeparator.Text = ""; thisPersonFieldElement.SecondGroupLastPersonSeparator.Text = ""; AfterFormatPersonEventArgs afp; thisPersonFieldElement.PersonFormatter.AfterFormatPerson += (sender, e) => { afp = (AfterFormatPersonEventArgs)e; #region Full Identity if (compareResult.Identity == PersonTeamsIdentity.Full) { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else { afp.TextUnits.Clear(); } } #endregion #region Partial Identity else { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else if (afp.Index < compareResult.IdenticalPersonsCount) { afp.TextUnits.Clear(); } else { afp.TextUnits.Insert(0, personSeparator); } } #endregion }; return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //return handled = true if this macro generates the output (as an IEnumerable<ITextUnit>); the standard output will be suppressed //return handled = false if you want Citavi to produce the standard output; handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } #region ThisPersonFieldElement PersonFieldElement thisPersonFieldElement = GetFirstPersonFieldElement(componentPart); if (thisPersonFieldElement == null || thisPersonFieldElement.SuppressOutput) { return(null); } #endregion #region ThesePersons IEnumerable <Person> thesePersons = thisPersonFieldElement.GetPersons(citation); if (thesePersons == null || !thesePersons.Any()) { return(null); } #endregion #region PreviousPersonFieldElement PersonFieldElement previousPersonFieldElement = GetPreviousPersonFieldElement(thisPersonFieldElement, template, citation); if (previousPersonFieldElement == null) { return(null); } #endregion #region PreviousPersons IEnumerable <Person> previousPersons = previousPersonFieldElement.GetPersons(citation); if (previousPersons == null || !previousPersons.Any()) { return(null); } #endregion PersonTeamsCompareResult compareResult = GetPersonTeamsIdentityAndGenderStructure(thesePersons, previousPersons); if (compareResult.Identity == PersonTeamsIdentity.None) { return(null); } bool handleAlsoPartialIdentity = true; //if true, both of the following cases (1) and (2) will be treated. Otherwise, //if false, only case (1) will be treated //(1) Watson, Mary / Smith, Emma, »An interesting contribution«, in: iidem (Eds.), Edited book with 2 editors, London 2012. //(2) Watson, Mary / Smith, Emma, »A rather boring contribution«, in: iidem / Green, Peter (Eds.), Edited book with 3 editors, London 2012. if (compareResult.Identity == PersonTeamsIdentity.Partial && !handleAlsoPartialIdentity) { return(null); } //if you want "ders."/"dies." written in italics or other font styles, choose the desired option, for example FontStyle.Italic, FontStyle.Bold or FontStyle.SmallCaps LiteralTextUnit idemSingularMaleLiteral = new LiteralTextUnit("ders.", FontStyle.Neutral); LiteralTextUnit idemSingularFemaleLiteral = new LiteralTextUnit("dies.", FontStyle.Neutral); LiteralTextUnit idemSingularNeutralLiteral = new LiteralTextUnit("dass.", FontStyle.Neutral); LiteralTextUnit idemPluralLiteral = new LiteralTextUnit("dies.", FontStyle.Neutral); //NOTE: If you want a prefix such as "In: " and a suffix " (Hrsg.)", you can define them as group prefix and suffix on the field element inside the component part editor //CAUTION: This script will get more complex, if the separators between persons differ from group to group of for the last person LiteralTextUnit personSeparator = new LiteralTextUnit(thisPersonFieldElement.FirstGroupPersonSeparator.Text, thisPersonFieldElement.FirstGroupPersonSeparator.FontStyle); //we remove all separators, because some person names will have to be suppressed and we want to avoid excess separators such as the /'s in idem///John Smith thisPersonFieldElement.FirstGroupPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupLastPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupToSecondGroupSeparator.Text = ""; thisPersonFieldElement.SecondGroupPersonSeparator.Text = ""; thisPersonFieldElement.SecondGroupLastPersonSeparator.Text = ""; AfterFormatPersonEventArgs afp; thisPersonFieldElement.PersonFormatter.AfterFormatPerson += (sender, e) => { afp = (AfterFormatPersonEventArgs)e; #region Full Identity if (compareResult.Identity == PersonTeamsIdentity.Full) { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else { afp.TextUnits.Clear(); } } #endregion #region Partial Identity else { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else if (afp.Index < compareResult.IdenticalPersonsCount) { afp.TextUnits.Clear(); } else { afp.TextUnits.Insert(0, personSeparator); } } #endregion }; return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //Version 2.0: Corrected bug that organizations were not considered because of missing AfterFormatOrganization event handler handled = false; if (citation == null || citation.Reference == null || citation.CitationManager == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } if (template == null) { return(null); } //filter deactivates itself, if the bibliography is NOT YET completely sorted //this is necessary to avoid that this filter in turn changes the sort order, that it depends upon if (citation.CitationManager.BibliographyCitations.IsSorted == false) { return(null); } //make sure the current componentPart is the FIRST inside the template if (template.ComponentParts == null || template.ComponentParts.Count == 0) { return(null); } if (template.ComponentParts[0].Id != componentPart.Id) { return(null); } #region ThisBibliographyCitation var thisBibliographyCitation = citation as BibliographyCitation; if (thisBibliographyCitation == null) { return(null); } #endregion ThisBibliographyCitation #region PreviousBibliographyCitation var previousBibliographyCitation = GetPreviousVisibleBibliographyCitation(thisBibliographyCitation); if (previousBibliographyCitation == null) { return(null); } if (previousBibliographyCitation.Reference == null) { return(null); } if (previousBibliographyCitation.NoBib == true) { return(null); } #endregion PreviousBibliographyCitation #region ThisTemplate var thisTemplate = thisBibliographyCitation.Template; if (thisTemplate == null) { return(null); } #endregion ThisTemplate #region PreviousTemplate var previousTemplate = previousBibliographyCitation.Template; if (previousTemplate == null) { return(null); } #endregion PreviousTemplate #region ThisPersonFieldElement var thisPersonFieldElement = ( componentPart.Elements != null && componentPart.Elements.Count > 0 ? componentPart.Elements[0] : null ) as PersonFieldElement; if (thisPersonFieldElement == null) { return(null); } #endregion ThisPersonFieldElement #region PreviousPersonFieldElement var previousPersonFieldElement = ( previousTemplate.ComponentParts != null && previousTemplate.ComponentParts.Count > 0 && previousTemplate.ComponentParts[0].Elements != null && previousTemplate.ComponentParts[0].Elements.Count > 0 ? previousTemplate.ComponentParts[0].Elements[0] : null ) as PersonFieldElement; if (previousPersonFieldElement == null) { return(null); } #endregion PreviousPersonFieldElement #region ThesePersons //we DO have a valid citation/reference a previous citation/reference, so we can compare their persons IEnumerable <Person> thesePersons = thisBibliographyCitation.Reference.GetValue(thisPersonFieldElement.PropertyId) as IEnumerable <Person>; if (thesePersons == null || thesePersons.Count() == 0) { return(null); } #endregion ThesePersons #region PreviousPersons IEnumerable <Person> previousPersons = previousBibliographyCitation.Reference.GetValue(previousPersonFieldElement.PropertyId) as IEnumerable <Person>; if (previousPersons == null || previousPersons.Count() == 0) { return(null); } bool failedOnce = false; #endregion PreviousPersons //since we are still here, we DO have persons in both cases to compare PersonTeamsCompareResult compareResult = GetPersonTeamsIdentityAndGenderStructure(thesePersons, previousPersons); if (compareResult.Identity == PersonTeamsIdentity.None) { return(null); } bool handleAlsoPartialIdentity = true; //if true, both of the following cases (1) and (2) will be treated. Otherwise, //if false, only case (1) will be treated //(1) Watson, Mary / Smith, Emma, »An interesting contribution«, in: iidem (Eds.), Edited book with 2 editors, London 2012. //(2) Watson, Mary / Smith, Emma, »A rather boring contribution«, in: iidem / Green, Peter (Eds.), Edited book with 3 editors, London 2012. if (compareResult.Identity == PersonTeamsIdentity.Partial && !handleAlsoPartialIdentity) { return(null); } //if you want "ders."/"dies." written in italics or other font styles, choose the desired option, for example FontStyle.Italic, FontStyle.Bold or FontStyle.SmallCaps LiteralTextUnit idemSingularMaleLiteral = new LiteralTextUnit("Ders.", FontStyle.Neutral); LiteralTextUnit idemSingularFemaleLiteral = new LiteralTextUnit("Dies.", FontStyle.Neutral); LiteralTextUnit idemSingularNeutralLiteral = new LiteralTextUnit("Dass.", FontStyle.Neutral); LiteralTextUnit idemPluralLiteral = new LiteralTextUnit("Dies.", FontStyle.Neutral); //CAUTION: This script will get more complex, if the separators between persons differ from group to group os for the last person LiteralTextUnit personSeparator = new LiteralTextUnit(thisPersonFieldElement.FirstGroupPersonSeparator.Text, thisPersonFieldElement.FirstGroupPersonSeparator.FontStyle); //we remove all separators, because some person names will have to be suppressed and we want to avoid excess separators such as the /'s in idem///John Smith thisPersonFieldElement.FirstGroupPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupLastPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupToSecondGroupSeparator.Text = ""; thisPersonFieldElement.SecondGroupPersonSeparator.Text = ""; thisPersonFieldElement.SecondGroupLastPersonSeparator.Text = ""; AfterFormatPersonEventArgs afp; thisPersonFieldElement.PersonFormatter.AfterFormatPerson += (sender, e) => { afp = (AfterFormatPersonEventArgs)e; #region Full Identity if (compareResult.Identity == PersonTeamsIdentity.Full) { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else { afp.TextUnits.Clear(); //we suppress the output of the person's name } } #endregion #region Partial Identity else { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else if (afp.Index < compareResult.IdenticalPersonsCount) { afp.TextUnits.Clear(); //we suppress the output of the person's name } else { afp.TextUnits.Insert(0, personSeparator); //we allow output of the person's name but inject the separator again } } #endregion }; AfterFormatOrganizationEventArgs afo; thisPersonFieldElement.PersonFormatter.AfterFormatOrganization += (sender, e) => { afo = (AfterFormatOrganizationEventArgs)e; #region Full Identity if (compareResult.Identity == PersonTeamsIdentity.Full) { if (afo.Index == 0) { afo.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afo.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afo.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afo.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afo.TextUnits.Add(idemPluralLiteral); } break; } } else { afo.TextUnits.Clear(); //we suppress the output of the person's name } } #endregion #region Partial Identity else { if (afo.Index == 0) { afo.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afo.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afo.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afo.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afo.TextUnits.Add(idemPluralLiteral); } break; } } else if (afo.Index < compareResult.IdenticalPersonsCount) { afo.TextUnits.Clear(); //we suppress the output of the person's name } else { afo.TextUnits.Insert(0, personSeparator); //we allow output of the person's name but inject the separator again } } #endregion }; return(null); }