Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle a Shape having formula - AlternateContent #706

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seyong-um
Copy link

@seyong-um seyong-um commented May 3, 2021

Symptom: Once a formula added into any type of shape, then Slide.shapes will not handle the Shape
Reason: The shape is represented inside of AlternateContent element.
Solution: Select first item of AlternateContent as a content.

Symptom: Once a formula added into any type of shape, then Slide.shapes will not handle the Shape
Reason: The shape is represented inside of AlternateContent element.
Solution: Select first item of AlternateContent as a content.
victai pushed a commit to victai/python-pptx that referenced this pull request Jun 12, 2021
@stephen-farris-jhuapl-edu
Copy link

stephen-farris-jhuapl-edu commented May 24, 2022

Any chance someone could review this MR? I'm running into this bug myself, and would love to have a fix. The workaround, to not have any equations in my slide deck, isn't a great option. I don't know the code-base well enough to review this MR myself. In my case this causes tables containing equations to not be visible to my code, failing silently.

@programmarchy
Copy link

This PR bakes in the assumption that the user wants a specific "choice" (in the markup compatibility parlance).

Another approach would be to explicitly define this as a new shape node. The XML can be parsed like:

class CT_AlternateContent(BaseOxmlElement):
  veChoice = ZeroOrMore('ve:Choice')
  veFallback = OneAndOnlyOne('ve:Fallback')

register_element_cls("ve:AlternateContent", CT_AlternateContent)
register_element_cls("ve:Choice", CT_GroupShape)
register_element_cls("ve:Fallback", CT_GroupShape)

Then maybe produce a MarkupCompatibility shape from the BaseShapeFactory?

  • MarkupCompatibility(BaseShape)
    • choices: returns an array of GroupShape, corresponding to each ve:Choice element
    • fallback: returns a GroupShape, corresponding to the e:Fallback element

For the example with equations, the most likely scenario is you traverse slide.shapes and, when encountering a MarkupCompatibility instance, you select the first choice which would contain the "missing" table as well as the equation nodes.

@programmarchy
Copy link

programmarchy commented Aug 23, 2022

@scanny Do you have any interest in supporting these "AlternateContent" elements? They are essentially conditional branches of XML that allow fallbacks for features that may not be backwards compatible with older versions of PowerPoint.

PowerPoint may place these branches near the root of the shape tree, instead of tightly bounding a feature. So if you have math formulas inside a table, then that table won't be enumerated as a shape because it will be nested in one of these branches.

For example, if you have a table containing "math stuff", needing >=2010, then the XML tree may look like:

<p:spTree>
  <mc:AlternateContent xmlns:mathStuff="http://schemas.microsoft.com/office/drawing/2010/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <mc:Choice Requires="mathStuff"> <!-- specifies what features are needed for compatibility -->
      <table>
        ...
        <!-- feature that not be compatible with every version -->
        <mathStuff:formula>
          ...
        </mathStuff:formula>
      </table>
    </mc:Choice>
    <mc:Fallback>
      <table>
        ...
        <!-- feature would be missing or substituted -->
      </table>
    </mc:Fallback>
</p:spTree>

If you're interested, guidance on implementation would be appreciated. There's an implementation in this PR, and I've also proposed an alternative. Thanks.

@AM-ash-OR-AM-I
Copy link

AM-ash-OR-AM-I commented Jun 5, 2023

@seyong-um
Hey! Your PR seemed to have solved most of the issues with parsing equations but I'm still having some issues could you please look at issue #892?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants