function l.italicizeTypeName(typeName)
if typeName and not (string.find(typeName, "<", 1, true) or string.find(typeName, ">", 1, true)) then
typeName = TaxonItalics.italicizeTaxonName(typeName, false, false)
end
return typeName
end  
-- **************************** Speciesbox support *****************************  
-- =============================================================================
-- l.genusOf(str) extracts the genus from a string. Normally this will be the
-- first word of the string (e.g. given 'Bellis perennis' it returns 'Bellis').
-- It also handles a string containing a nothogenus with a spaced × (e.g. given
-- '× Heucherella tiarelloides' it returns '× Heucherella').
-- =============================================================================  
function l.genusOf(str)
local res = mw.ustring.match(str, '^[^%s]*', 1)
if res == mw.ustring.char(215) then
res = res .. ' ' .. mw.ustring.match(str, '^[^%s]*', 3)
end
return res
end  
-- =============================================================================
-- l.doSpeciesboxName(name, taxon, genus, species, basePageTitle, italicTitle)
-- returns a name for a taxobox created by Template:Speciesbox. The name will be
-- italicized if appropriate. It also generates code to italicize the page title
-- if appropropriate. In both cases the test for italicization is that the base
-- taxon name (stripped of any disambiguation or qualifier) is the same as the
-- base page title.
-- =============================================================================  
function p.speciesboxName
local name = .args[1] or ''
local taxon = .args[2] or ''
local genus = .args[3] or ''
local species = .args[4] or ''
local basePageTitle = .args[5] or ''
local italicTitle = .args[6] or ''
return l.doSpeciesboxName(name, taxon, genus, species, basePageTitle, italicTitle)
end  
function l.doSpeciesboxName(name, taxon, genus, species, basePageTitle, italicTitle)
if taxon ~= '' then
genus = mw.ustring.gsub(l.genusOf(taxon), '/.*$', '', 1) -- strip any qualifier
else
genus = mw.ustring.gsub(mw.ustring.gsub(genus, '%s+%b$', *, 1), '/.*$', *, 1) -- strip any disambig and qualifier
if species == '' then taxon = genus
else taxon = genus .. ' ' .. species
end
end
local italicizeP = italicTitle ~= 'no' and (basePageTitle == taxon or basePageTitle == genus) -- use basePageTitle to match taxon/genus
-- deal with taxobox name (i.e. its caption)
if name == '' then
name = basePageTitle
if italicizeP then name = TaxonItalics.italicizeTaxonName(name, false, false) end
end
-- deal with page title
if italicizeP then
local pageTitle = mw.title.getCurrentTitle.text -- formatting the page title with DISPLAYTITLE needs the full page title
if italicTitle ~= 'test' then
pageTitle = TaxonItalics.italicizeTaxonName(pageTitle, false, false, true) -- format pageTitle, not italicizing any parenthesized term
local nsText = mw.title.getCurrentTitle.nsText -- for drafts and other pages not in mainspace
if nsText ~= '' then
pageTitle = nsText .. ':' .. pageTitle
end
mw.getCurrentFrame:callParserFunction('DISPLAYTITLE', pageTitle)
else
name = name .. ' \\Italic title\\ ' .. pageTitle -- for testing and debugging
end
end
return name
end  
-- =============================================================================
-- =============================================================================
function p.infraspeciesboxName
local name = .args[1] or ''
local genus = .args[2] or ''
local species = .args[3] or ''
local ct = .args[4] or ''
local infraspecies = .args[5] or ''
local basePageTitle = .args[6] or ''
local italicTitle = .args[7] or ''
return l.doinfraspeciesboxName(name, genus, species, ct, infraspecies, basePageTitle, italicTitle)
end  
function l.doinfraspeciesboxName(name, genus, species, ct, infraspecies, basePageTitle, italicTitle)
genus = mw.ustring.gsub(mw.ustring.gsub(genus, '%s+%b$', *, 1), '/.*$', *, 1) -- strip any disambig and qualifier
local taxon = genus .. ' ' .. species
if ct == '' then taxon = taxon .. ' ' .. infraspecies
else taxon = taxon .. ' ' .. ct .. ' ' .. infraspecies
end
local italicizeP = italicTitle ~= 'no' and (basePageTitle == taxon) -- use basePageTitle to match taxon
-- deal with taxobox name (i.e. its caption)
if name == '' then
name = basePageTitle
if italicizeP then name = TaxonItalics.italicizeTaxonName(name, false, false) end
end
-- deal with page title
if italicizeP then
local pageTitle = mw.title.getCurrentTitle.text -- formatting the page title with DISPLAYTITLE needs the full page title
pageTitle = TaxonItalics.italicizeTaxonName(pageTitle, false, false, true) -- format pageTitle, not italicizing any parenthesized term
if italicTitle ~= 'test' then
mw.getCurrentFrame:callParserFunction('DISPLAYTITLE', pageTitle)
else
name = name .. ' \\Italic title\\ ' .. pageTitle -- for testing and debugging
end
end
return name
end  
return p