Repository: sympy/sympy

Issue:
Strangely behaved gamma_trace (gamma matrix trace)
I am trying to use the high energy physics module of SymPy to compute traces of gamma matrices using the dedicated function `sympy.physics.hep.gamma_matrices.gamma_trace`.  I have come accross the following strange behaviour: in some cases, the trace of a sum is not computed to be the sum of the traces. Here is an example:

```python
from sympy import Symbol
from sympy.tensor.tensor import tensor_indices, tensorhead
from sympy.physics.hep.gamma_matrices import GammaMatrix as G, gamma_trace, LorentzIndex

pi, ki, pf = tensorhead("pi, ki, pf", [LorentzIndex], [[1]])
i0, i1, i2, i3, i4 = tensor_indices("i0:5", LorentzIndex)
x = Symbol("x")
pis = pi(i2) * G(-i2)
kis = ki(i3) * G(-i3)
pfs = pf(i4) * G(-i4)

# Show the trace of A + B
print gamma_trace(pfs * G(i0) * kis * G(i1) * pis * G(-i1) * kis * G(-i0) + pfs * G(i0) * kis * G(i1) * pis * x * G(-i0) * pi(-i1))
# Show the trace of A
print gamma_trace(pfs * G(i0) * kis * G(i1) * pis * G(-i1) * kis * G(-i0))
# Show the trace of B
print gamma_trace(pfs * G(i0) * kis * G(i1) * pis * x * G(-i0) * pi(-i1))
```

It may be a normal behaviour, but I couldn't find any hint in the docs dedicated to the module.

Discussion:

Patch:
diff --git a/.mailmap b/.mailmap
index e832c7be1e..03eca177f6 100644
--- a/.mailmap
+++ b/.mailmap
@@ -588,6 +588,8 @@ Gilbert Gede <gilbertgede@gmail.com> <ggede@ucdavis.edu>
 Gilles Schintgen <gschintgen@hambier.lu>
 Gina <Dr-G@users.noreply.github.com>
 Gleb Siroki <g.shiroki@gmail.com>
+Glenn Horton-Smith <glenn.hortonsmith@gmail.com>
+Glenn Horton-Smith <glenn.hortonsmith@gmail.com> Glenn Horton-Smith <gahs@phys.ksu.edu>
 GolimarOurHero <metalera94@hotmail.com>
 Goutham Lakshminarayan <dl.goutham@gmail.com> Goutham <devnull@localhost>
 Govind Sahai <gsiitbhu@gmail.com>
diff --git a/doc/src/conf.py b/doc/src/conf.py
index ceadb78fed..112d044f36 100644
--- a/doc/src/conf.py
+++ b/doc/src/conf.py
@@ -36,50 +36,16 @@
               'myst_parser', 'convert-svg-to-pdf', 'sphinx.ext.intersphinx'
               ]
 
-# Add redirects here. This should be done whenever a page that is in the
-# existing release docs is moved somewhere else so that the URLs don't break.
-# The format is
-
-# "page/path/without/extension": "../relative_path_with.html"
-
-# Note that the html path is relative to the redirected page. Always test the
-# redirect manually (they aren't tested automatically). See
-# https://documatt.gitlab.io/sphinx-reredirects/usage.html
-
 redirects = {
-    "guides/getting_started/install": "../../install.html",
-    "documentation-style-guide": "contributing/documentation-style-guide.html",
-    "gotchas": "explanation/gotchas.html",
-    "special_topics/classification": "../explanation/classification.html",
-    "special_topics/finite_diff_derivatives": "../explanation/finite_diff_derivatives.html",
-    "special_topics/intro": "../explanation/index.html",
-    "special_topics/index": "../explanation/index.html",
-    "modules/index": "../reference/index.html",
-    "modules/physics/index": "../../reference/public/physics/index.html",
-
-    "guides/contributing/index": "../../contributing/index.html",
-    "guides/contributing/dev-setup": "../../contributing/dev-setup.html",
-    "guides/contributing/dependencies": "../../contributing/dependencies.html",
-    "guides/contributing/build-docs": "../../contributing/build-docs.html",
-    "guides/contributing/debug": "../../contributing/debug.html",
-    "guides/contributing/docstring": "../../contributing/docstring.html",
-    "guides/documentation-style-guide": "../../contributing/contributing/documentation-style-guide.html",
-    "guides/make-a-contribution": "../../contributing/make-a-contribution.html",
-    "guides/contributing/deprecations": "../../contributing/deprecations.html",
-
-    "tutorial/preliminaries": "../tutorials/intro-tutorial/preliminaries.html",
-    "tutorial/intro": "../tutorials/intro-tutorial/intro.html",
-    "tutorial/gotchas": "../tutorials/intro-tutorial/gotchas.html",
-    "tutorial/features": "../tutorials/intro-tutorial/features.html",
-    "tutorial/next": "../tutorials/intro-tutorial/next.html",
-    "tutorial/basic_operations": "../tutorials/intro-tutorial/basic_operations.html",
-    "tutorial/printing": "../tutorials/intro-tutorial/printing.html",
-    "tutorial/simplification": "../tutorials/intro-tutorial/simplification.html",
-    "tutorial/calculus": "../tutorials/intro-tutorial/calculus.html",
-    "tutorial/solvers": "../tutorials/intro-tutorial/solvers.html",
-    "tutorial/matrices": "../tutorials/intro-tutorial/matrices.html",
-    "tutorial/manipulation": "../tutorials/intro-tutorial/manipulation.html",
-
+    "install.rst": "guides/getting_started/install.html",
+    "documentation-style-guide.rst": "guides/contributing/documentation-style-guide.html",
+    "gotchas.rst": "explanation/gotchas.html",
+    "special_topics/classification.rst": "explanation/classification.html",
+    "special_topics/finite_diff_derivatives.rst": "explanation/finite_diff_derivatives.html",
+    "special_topics/intro.rst": "explanation/index.html",
+    "special_topics/index.rst": "explanation/index.html",
+    "modules/index.rst": "reference/public/index.html",
+    "modules/physics/index.rst": "reference/physics/index.html",
 }
 
 html_baseurl = "https://docs.sympy.org/latest/"
@@ -396,10 +362,6 @@
 intersphinx_mapping = {
     'matplotlib': ('https://matplotlib.org/stable/', None)
 }
-# Require :external: to reference intersphinx. Prevents accidentally linking
-# to something from matplotlib.
-intersphinx_disabled_reftypes = ['*']
-
 # Requried for linkcode extension.
 # Get commit hash from the external file.
 commit_hash_filepath = '../commit_hash.txt'
diff --git a/doc/src/contributing/index.rst b/doc/src/contributing/index.rst
deleted file mode 100644
index 26a9fcd3ae..0000000000
--- a/doc/src/contributing/index.rst
+++ /dev/null
@@ -1,24 +0,0 @@
-.. _contributing:
-
-==============
- Contributing
-==============
-
-The contributing guide goes over the details necessary to contribute to SymPy.
-See also the full `Development Workflow
-<https://github.com/sympy/sympy/wiki/Development-workflow>`_ guide on the
-SymPy wiki.
-
-**Content**
-
-.. toctree::
-   :maxdepth: 2
-
-   dev-setup.rst
-   dependencies.md
-   build-docs.rst
-   debug.rst
-   docstring.rst
-   documentation-style-guide.rst
-   make-a-contribution.rst
-   deprecations.md
diff --git a/doc/src/explanation/gotchas.rst b/doc/src/explanation/gotchas.rst
index adf3e96974..aaedc01476 100644
--- a/doc/src/explanation/gotchas.rst
+++ b/doc/src/explanation/gotchas.rst
@@ -9,13 +9,13 @@ Gotchas and Pitfalls
 Introduction
 ============
 
-SymPy runs under the `Python Programming Language <https://www.python.org/>`_,
-so there are some things that may behave differently than they do in other,
-independent computer algebra systems like Maple or Mathematica. These are some
-of the gotchas and pitfalls that you may encounter when using SymPy. See also
-the `FAQ <https://github.com/sympy/sympy/wiki/Faq>`_, the :ref:`introductory
-tutorial<intro-tutorial>`, the remainder of the SymPy Docs, and the `official
-Python Tutorial <https://docs.python.org/3/tutorial/>`_.
+SymPy runs under the `Python Programming Language
+<https://www.python.org/>`_, so there are some things that may behave
+differently than they do in other, independent computer algebra systems
+like Maple or Mathematica.  These are some of the gotchas and pitfalls
+that you may encounter when using SymPy.  See also the `FAQ
+<https://github.com/sympy/sympy/wiki/Faq>`_, the :ref:`Tutorial<tutorial>`, the
+remainder of the SymPy Docs, and the `official Python Tutorial <https://docs.python.org/3/tutorial/>`_.
 
 
 If you are already familiar with C or Java, you might also want to look
diff --git a/doc/src/explanation/index.rst b/doc/src/explanation/index.rst
index e24117ecbb..098e93e890 100644
--- a/doc/src/explanation/index.rst
+++ b/doc/src/explanation/index.rst
@@ -1,13 +1,10 @@
-.. _explanations:
+.. _explanation:
 
-==============
- Explanations
-==============
+=============
+ Explanation
+=============
 
-
-Explanations provide in-depth discussions about select SymPy features. These
-topic guides talk about things like the motivation behind design decisions,
-technical implementation details, and opinionated recommendations.
+This section contains a discussion of in-depth feature details, specialized topics and common SymPy pitfalls.
 
 **Content**
 
diff --git a/doc/src/contributing/build-docs.rst b/doc/src/guides/contributing/build-docs.rst
similarity index 100%
rename from doc/src/contributing/build-docs.rst
rename to doc/src/guides/contributing/build-docs.rst
diff --git a/doc/src/contributing/debug.rst b/doc/src/guides/contributing/debug.rst
similarity index 100%
rename from doc/src/contributing/debug.rst
rename to doc/src/guides/contributing/debug.rst
diff --git a/doc/src/contributing/dependencies.md b/doc/src/guides/contributing/dependencies.md
similarity index 100%
rename from doc/src/contributing/dependencies.md
rename to doc/src/guides/contributing/dependencies.md
diff --git a/doc/src/contributing/deprecations.md b/doc/src/guides/contributing/deprecations.md
similarity index 100%
rename from doc/src/contributing/deprecations.md
rename to doc/src/guides/contributing/deprecations.md
diff --git a/doc/src/contributing/dev-setup.rst b/doc/src/guides/contributing/dev-setup.rst
similarity index 100%
rename from doc/src/contributing/dev-setup.rst
rename to doc/src/guides/contributing/dev-setup.rst
diff --git a/doc/src/contributing/docstring.rst b/doc/src/guides/contributing/docstring.rst
similarity index 100%
rename from doc/src/contributing/docstring.rst
rename to doc/src/guides/contributing/docstring.rst
diff --git a/doc/src/contributing/documentation-style-guide.rst b/doc/src/guides/contributing/documentation-style-guide.rst
similarity index 99%
rename from doc/src/contributing/documentation-style-guide.rst
rename to doc/src/guides/contributing/documentation-style-guide.rst
index faf30de7e7..eb85822da2 100644
--- a/doc/src/contributing/documentation-style-guide.rst
+++ b/doc/src/guides/contributing/documentation-style-guide.rst
@@ -1,5 +1,3 @@
-.. _documentation-style-guide:
-
 =====================
 Docstring Style Guide
 =====================
diff --git a/doc/src/guides/contributing/index.rst b/doc/src/guides/contributing/index.rst
new file mode 100644
index 0000000000..d91e24a707
--- /dev/null
+++ b/doc/src/guides/contributing/index.rst
@@ -0,0 +1,21 @@
+.. _contributing:
+
+============================
+Contributing to SymPy
+============================
+
+This section discusses the necessary steps and guidelines required to contribute to the SymPy project. The TOC has links to the detailed development process.
+
+**Content**
+
+.. toctree::
+   :maxdepth: 2
+
+   dev-setup.rst
+   dependencies.md
+   build-docs.rst
+   debug.rst
+   docstring.rst
+   documentation-style-guide.rst
+   make-a-contribution.rst
+   deprecations.md
diff --git a/doc/src/contributing/make-a-contribution.rst b/doc/src/guides/contributing/make-a-contribution.rst
similarity index 100%
rename from doc/src/contributing/make-a-contribution.rst
rename to doc/src/guides/contributing/make-a-contribution.rst
diff --git a/doc/src/guides/getting_started/index.rst b/doc/src/guides/getting_started/index.rst
new file mode 100644
index 0000000000..9ce65499a6
--- /dev/null
+++ b/doc/src/guides/getting_started/index.rst
@@ -0,0 +1,19 @@
+.. _get_started:
+
+Getting Started
+===============
+
+SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer
+algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible
+and easily extensible. SymPy is written entirely in Python.
+
+SymPy is…
+
+- **Free**: Licensed under BSD, SymPy is free both as in speech and as in beer.
+- **Python-based**: SymPy is written entirely in Python and uses Python for its language.
+- **Lightweight**: SymPy only depends on mpmath, a pure Python library for arbitrary floating point arithmetic, making it easy to use.
+- **A library**: Beyond use as an interactive tool, SymPy can be embedded in other applications and extended with custom functions.
+
+.. toctree::
+
+   install.rst
diff --git a/doc/src/install.md b/doc/src/guides/getting_started/install.md
similarity index 99%
rename from doc/src/install.md
rename to doc/src/guides/getting_started/install.md
index 6a10ac9cc3..006ee5e961 100644
--- a/doc/src/install.md
+++ b/doc/src/guides/getting_started/install.md
@@ -85,7 +85,7 @@ From here, execute some simple SymPy statements like the ones below:
 log(x)
 ```
 
-For a starter guide on using SymPy effectively, refer to the {ref}`intro-tutorial`.
+For a starter guide on using SymPy effectively, refer to the {ref}`tutorial`.
 
 (mpmath-install)=
 ## mpmath
diff --git a/doc/src/guides/index.rst b/doc/src/guides/index.rst
index 915780c063..04e06591fa 100644
--- a/doc/src/guides/index.rst
+++ b/doc/src/guides/index.rst
@@ -1,20 +1,25 @@
 .. _guides:
 
-===============
+==============
  How-to Guides
-===============
+==============
 
-How-to guides are step-by-step instructions on how to do specific tasks.
+The SymPy Guide discusses common developer process required to get started,
+and contributing to the SymPy project. It includes sections on installation, developer
+setup, but also common code and documentation style guides. It also covers topic areas
+on booleans and the core assumptions module.
 
 For a deeper and elaborate exploration of other SymPy topics, see the
-:ref:`Explanations <explanations>` and  :ref:`API reference
-<reference>` sections.
+section :ref:`Explanation <explanation>` and the :ref:`API reference <reference>` for
+a module break down.
 
 .. toctree::
    :maxdepth: 2
 
+   getting_started/index.rst
    assumptions.rst
    booleans.rst
    custom-functions.md
    solving/index.md
+   contributing/index.rst
    ../citing.md
diff --git a/doc/src/index.rst b/doc/src/index.rst
index 92e400667c..e668eb31d2 100644
--- a/doc/src/index.rst
+++ b/doc/src/index.rst
@@ -1,5 +1,9 @@
 .. _documentation:
 
+.. SymPy documentation master file, created by sphinx-quickstart.py on Sat Mar 22 19:34:32 2008.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
 .. module:: sympy
 
 Welcome to SymPy's documentation!
@@ -8,56 +12,56 @@ Welcome to SymPy's documentation!
 A `PDF version of these docs <https://github.com/sympy/sympy/releases>`_ is also available.
 
 `SymPy <https://sympy.org>`_ is a Python library for symbolic mathematics.
-If you are new to SymPy, start with the :ref:`introductory tutorial <intro-tutorial>`.
+If you are new to SymPy, start with the :ref:`Tutorial <tutorial>`.
 
 This is the central page for all of SymPy's documentation.
 
 ==================================================================
 
-:ref:`Installation <installation>`
-----------------------------------
+..  rst-class:: column
+
+:ref:`Tutorials <tutorial>`
+-------------------------------------------------------
 
-Instructions on how to install SymPy.
+Tutorials introduce SymPy features to people who are new to the project. It includes
+installation instructions, a basic introduction to SymPy operations and common gotchas.
 
-:ref:`Tutorials <tutorials>`
-----------------------------
 
-Tutorials are the best place to start for anyone new to SymPy or one of
-SymPy's features.
+..  rst-class:: column
 
 :ref:`How-to Guides <guides>`
------------------------------
+-------------------------------------------------------
 
-How-to guides are step-by-step instructions on how to do specific tasks.
+These are step-by-step instructions on how to do different key developer tasks. It details
+instructions on installing SymPy from source for development. The development setup and workflow
+is also discussed with elaborate details on debugging, building the docs, and general guidelines
+on writing documentation and docstrings.
 
-:ref:`Explanations <explanations>`
-----------------------------------
 
-Explanations provide in-depth discussions about select SymPy features. These
-topic guides talk about things like the motivation behind design decisions,
-technical implementation details, and opinionated recommendations.
+..  rst-class:: column clearfix
 
-:ref:`API Reference <reference>`
---------------------------------
+:ref:`Explanation <explanation>`
+-------------------------------------------------------
 
-The API reference is a detailed description of the SymPy API. Every SymPy
-function and class is enumerated here with detailed information on what each
-function does.
+Intermediate SymPy users and developers should reference this category of documentation
+for common pitfalls and advanced topics. The core SymPy features like variables, functions,
+symbolic expressions are detailed but it does not completely exhaust all SymPy operations.
 
-:ref:`Contributing <contributing>`
-----------------------------------
 
-The contributing guide goes over the details necessary to contribute to SymPy.
-See also the full `Development Workflow
-<https://github.com/sympy/sympy/wiki/Development-workflow>`_ guide on the
-SymPy wiki.
+..  rst-class:: column
+
+:ref:`API Reference <reference>`
+-------------------------------------------------------
+
+This category has a detailed description of the SymPy API, it discusses
+what the different functions and modules do, their arguments and return values.
+
+..  rst-class:: clearfix row custom-headings
 
 .. toctree::
    :hidden:
 
-   install.md
-   tutorials/index.rst
+   tutorial/index.rst
    guides/index.rst
    explanation/index.rst
    reference/index.rst
-   contributing/index.rst
diff --git a/doc/src/modules/physics/mechanics/sympy_mechanics_for_autolev_users.rst b/doc/src/modules/physics/mechanics/sympy_mechanics_for_autolev_users.rst
index aebf4f24c2..960154ef21 100644
--- a/doc/src/modules/physics/mechanics/sympy_mechanics_for_autolev_users.rst
+++ b/doc/src/modules/physics/mechanics/sympy_mechanics_for_autolev_users.rst
@@ -702,7 +702,7 @@ scientific computing with Python.
 Links
 ----------
 
-:ref:`SymPy Introductory Tutorial <intro-tutorial>`
+:ref:`SymPy Tutorial <tutorial>`
 
 :ref:`SymPy Documentation <documentation>`
 
diff --git a/doc/src/modules/plotting.rst b/doc/src/modules/plotting.rst
index 14f3530025..660728079c 100644
--- a/doc/src/modules/plotting.rst
+++ b/doc/src/modules/plotting.rst
@@ -8,9 +8,9 @@ Introduction
 ------------
 
 The plotting module allows you to make 2-dimensional and 3-dimensional plots.
-Presently the plots are rendered using :external:mod:`matplotlib` as a
-backend. It is also possible to plot 2-dimensional plots using a
-:class:`~.TextBackend` if you do not have :external:mod:`matplotlib`.
+Presently the plots are rendered using :mod:`matplotlib` as a backend. It is
+also possible to plot 2-dimensional plots using a :class:`~.TextBackend` if you
+do not have :mod:`matplotlib`.
 
 The plotting module has the following functions:
 
diff --git a/doc/src/reference/index.rst b/doc/src/reference/index.rst
index 680793fc3f..0f8d3ebf5a 100644
--- a/doc/src/reference/index.rst
+++ b/doc/src/reference/index.rst
@@ -4,9 +4,9 @@
 API Reference
 =============
 
-This section contains a summary of SymPy modules, functions, classes, and
-methods. All functions and objects implemented in the ``sympy`` core
-subpackage are documented below.
+This section contains a summary of SymPy modules, that is to say
+functions and methods. All functions and objects implemented in the ``sympy``
+core subpackage are documented below.
 
 ..  rst-class:: column
 
diff --git a/doc/src/tutorials/intro-tutorial/basic_operations.rst b/doc/src/tutorial/basic_operations.rst
similarity index 100%
rename from doc/src/tutorials/intro-tutorial/basic_operations.rst
rename to doc/src/tutorial/basic_operations.rst
diff --git a/doc/src/tutorials/intro-tutorial/calculus.rst b/doc/src/tutorial/calculus.rst
similarity index 100%
rename from doc/src/tutorials/intro-tutorial/calculus.rst
rename to doc/src/tutorial/calculus.rst
diff --git a/doc/src/tutorials/intro-tutorial/features.rst b/doc/src/tutorial/features.rst
similarity index 100%
rename from doc/src/tutorials/intro-tutorial/features.rst
rename to doc/src/tutorial/features.rst
diff --git a/doc/src/tutorials/intro-tutorial/gotchas.rst b/doc/src/tutorial/gotchas.rst
similarity index 100%
rename from doc/src/tutorials/intro-tutorial/gotchas.rst
rename to doc/src/tutorial/gotchas.rst
diff --git a/doc/src/tutorials/intro-tutorial/index.rst b/doc/src/tutorial/index.rst
similarity index 95%
rename from doc/src/tutorials/intro-tutorial/index.rst
rename to doc/src/tutorial/index.rst
index 9979e6c1f9..a2e59c8bc6 100644
--- a/doc/src/tutorials/intro-tutorial/index.rst
+++ b/doc/src/tutorial/index.rst
@@ -1,8 +1,8 @@
-.. _intro-tutorial:
+.. _tutorial:
 
-=====================
-Introductory Tutorial
-=====================
+==========
+ Tutorials
+==========
 
 This tutorial aims to give an introduction to SymPy for someone who has not
 used the library before.  Many features of SymPy will be introduced in this
diff --git a/doc/src/tutorials/intro-tutorial/intro.rst b/doc/src/tutorial/intro.rst
similarity index 100%
rename from doc/src/tutorials/intro-tutorial/intro.rst
rename to doc/src/tutorial/intro.rst
diff --git a/doc/src/tutorials/intro-tutorial/manipulation.rst b/doc/src/tutorial/manipulation.rst
similarity index 100%
rename from doc/src/tutorials/intro-tutorial/manipulation.rst
rename to doc/src/tutorial/manipulation.rst
diff --git a/doc/src/tutorials/intro-tutorial/matrices.rst b/doc/src/tutorial/matrices.rst
similarity index 100%
rename from doc/src/tutorials/intro-tutorial/matrices.rst
rename to doc/src/tutorial/matrices.rst
diff --git a/doc/src/tutorial/next.rst b/doc/src/tutorial/next.rst
new file mode 100644
index 0000000000..f358a715a7
--- /dev/null
+++ b/doc/src/tutorial/next.rst
@@ -0,0 +1,10 @@
+What’s Next
+===========
+
+Congratulations on finishing the SymPy tutorial!
+
+If you are a developer interested in using SymPy in your code, please visit the :ref:`How-to Guides <guides>` which discuss key developer tasks.
+
+Intermediate SymPy users and developers might want to visit the :ref:`Explanation <explanation>` section for common pitfalls and advanced topics.
+
+The :ref:`SymPy API Reference <reference>` has a detailed description of the SymPy API.
diff --git a/doc/src/tutorials/intro-tutorial/preliminaries.rst b/doc/src/tutorial/preliminaries.rst
similarity index 100%
rename from doc/src/tutorials/intro-tutorial/preliminaries.rst
rename to doc/src/tutorial/preliminaries.rst
diff --git a/doc/src/tutorials/intro-tutorial/printing.rst b/doc/src/tutorial/printing.rst
similarity index 97%
rename from doc/src/tutorials/intro-tutorial/printing.rst
rename to doc/src/tutorial/printing.rst
index e29b26fdde..8e43c33c14 100644
--- a/doc/src/tutorials/intro-tutorial/printing.rst
+++ b/doc/src/tutorial/printing.rst
@@ -63,7 +63,7 @@ In any case, this is what will happen:
 - In the IPython QTConsole, if `\mathrm{\LaTeX}` is installed, it will enable a printer
   that uses `\mathrm{\LaTeX}`.
 
-  .. image:: ../../pics/ipythonqtconsole.png
+  .. image:: ../pics/ipythonqtconsole.png
      :height: 500
 
   If `\mathrm{\LaTeX}` is not installed, but Matplotlib is installed, it will use the
@@ -72,19 +72,19 @@ In any case, this is what will happen:
 
 - In the IPython notebook, it will use MathJax to render `\mathrm{\LaTeX}`.
 
-  .. image:: ../../pics/ipythonnotebook.png
+  .. image:: ../pics/ipythonnotebook.png
      :height: 250
 
 - In an IPython console session, or a regular Python session, it will use the
   Unicode pretty printer if the terminal supports Unicode.
 
-  .. image:: ../../pics/consoleunicode.png
+  .. image:: ../pics/consoleunicode.png
      :width: 700
 
 - In a terminal that does not support Unicode, the ASCII pretty printer is
   used.
 
-  .. image:: ../../pics/consoleascii.png
+  .. image:: ../pics/consoleascii.png
      :width: 700
 
 To explicitly not use `\mathrm{\LaTeX}`, pass ``use_latex=False`` to ``init_printing()``
diff --git a/doc/src/tutorials/intro-tutorial/simplification.rst b/doc/src/tutorial/simplification.rst
similarity index 100%
rename from doc/src/tutorials/intro-tutorial/simplification.rst
rename to doc/src/tutorial/simplification.rst
diff --git a/doc/src/tutorials/intro-tutorial/solvers.rst b/doc/src/tutorial/solvers.rst
similarity index 100%
rename from doc/src/tutorials/intro-tutorial/solvers.rst
rename to doc/src/tutorial/solvers.rst
diff --git a/doc/src/tutorials/index.rst b/doc/src/tutorials/index.rst
deleted file mode 100644
index e0826431ac..0000000000
--- a/doc/src/tutorials/index.rst
+++ /dev/null
@@ -1,19 +0,0 @@
-.. _tutorials:
-
-=========
-Tutorials
-=========
-
-
-Tutorials are the best place to start for anyone new to SymPy or one of
-SymPy's features.
-
-:ref:`Introductory Tutorial <intro-tutorial>`
-=============================================
-
-If you are new to SymPy, start here.
-
-.. toctree::
-   :hidden:
-
-   intro-tutorial/index.rst
diff --git a/doc/src/tutorials/intro-tutorial/next.rst b/doc/src/tutorials/intro-tutorial/next.rst
deleted file mode 100644
index f77e386efd..0000000000
--- a/doc/src/tutorials/intro-tutorial/next.rst
+++ /dev/null
@@ -1,19 +0,0 @@
-What’s Next
-===========
-
-Congratulations on finishing the SymPy tutorial!
-
-If you are a developer interested in using SymPy in your code, please visit
-the :ref:`How-to Guides <guides>` which discuss key developer tasks.
-
-Intermediate SymPy users and developers might want to visit the
-:ref:`Explanations <explanations>` section for common pitfalls and advanced
-topics.
-
-The :ref:`SymPy API Reference <reference>` has a detailed description of the
-SymPy API.
-
-If you are interested in contributing to SymPy, visit the :ref:`contribution
-guides <contributing>` and the full `Development Workflow
-<https://github.com/sympy/sympy/wiki/Development-workflow>`_ guide on the
-SymPy wiki.
diff --git a/sympy/physics/hep/gamma_matrices.py b/sympy/physics/hep/gamma_matrices.py
index 23284e4a92..3009550888 100644
--- a/sympy/physics/hep/gamma_matrices.py
+++ b/sympy/physics/hep/gamma_matrices.py
@@ -190,7 +190,7 @@ def gamma_trace(t):
 
     """
     if isinstance(t, TensAdd):
-        res = TensAdd(*[_trace_single_line(x) for x in t.args])
+        res = TensAdd(*[gamma_trace(x) for x in t.args])
         return res
     t = _simplify_single_line(t)
     res = _trace_single_line(t)
diff --git a/sympy/plotting/plot.py b/sympy/plotting/plot.py
index 440f11f118..5b3600080b 100644
--- a/sympy/plotting/plot.py
+++ b/sympy/plotting/plot.py
@@ -76,7 +76,7 @@ class Plot:
     For interactive work the function :func:`plot()` is better suited.
 
     This class permits the plotting of SymPy expressions using numerous
-    backends (:external:mod:`matplotlib`, textplot, the old pyglet module for SymPy, Google
+    backends (:mod:`matplotlib`, textplot, the old pyglet module for SymPy, Google
     charts api, etc).
 
     The figure can contain an arbitrary number of plots of SymPy expressions,
@@ -1329,7 +1329,7 @@ def __init__(self, parent):
     @staticmethod
     def get_segments(x, y, z=None):
         """ Convert two list of coordinates to a list of segments to be used
-        with Matplotlib's :external:class:`~matplotlib.collections.LineCollection`.
+        with Matplotlib's :class:`~matplotlib.collections.LineCollection`.
 
         Parameters
         ==========
@@ -1737,26 +1737,26 @@ def plot(*args, show=True, **kwargs):
     annotations : list, optional
         A list of dictionaries specifying the type of annotation
         required. The keys in the dictionary should be equivalent
-        to the arguments of the :external:mod:`matplotlib`'s
-        :external:meth:`~matplotlib.axes.Axes.annotate` method.
+        to the arguments of the :mod:`matplotlib`'s
+        :meth:`~matplotlib.axes.Axes.annotate` method.
 
     markers : list, optional
         A list of dictionaries specifying the type the markers required.
         The keys in the dictionary should be equivalent to the arguments
-        of the :external:mod:`matplotlib`'s :external:func:`~matplotlib.pyplot.plot()` function
+        of the :mod:`matplotlib`'s :func:`~matplotlib.pyplot.plot()` function
         along with the marker related keyworded arguments.
 
     rectangles : list, optional
         A list of dictionaries specifying the dimensions of the
         rectangles to be plotted. The keys in the dictionary should be
-        equivalent to the arguments of the :external:mod:`matplotlib`'s
-        :external:class:`~matplotlib.patches.Rectangle` class.
+        equivalent to the arguments of the :mod:`matplotlib`'s
+        :class:`~matplotlib.patches.Rectangle` class.
 
     fill : dict, optional
         A dictionary specifying the type of color filling required in
         the plot. The keys in the dictionary should be equivalent to the
-        arguments of the :external:mod:`matplotlib`'s
-        :external:meth:`~matplotlib.axes.Axes.fill_between` method.
+        arguments of the :mod:`matplotlib`'s
+        :meth:`~matplotlib.axes.Axes.fill_between` method.
 
     adaptive : bool, optional
         The default value is set to ``True``. Set adaptive to ``False``


Test patch:
diff --git a/sympy/physics/hep/tests/test_gamma_matrices.py b/sympy/physics/hep/tests/test_gamma_matrices.py
index 27509803f2..f5dc8f6d6f 100644
--- a/sympy/physics/hep/tests/test_gamma_matrices.py
+++ b/sympy/physics/hep/tests/test_gamma_matrices.py
@@ -3,6 +3,7 @@
     TensExpr, canon_bp
 from sympy.physics.hep.gamma_matrices import GammaMatrix as G, LorentzIndex, \
     kahane_simplify, gamma_trace, _simplify_single_line, simplify_gamma_expression
+from sympy import Symbol
 
 
 def _is_tensor_eq(arg1, arg2):
@@ -399,3 +400,26 @@ def test_gamma_matrix_trace():
     t = ps*ps*ps*ps*ps*ps*ps*ps
     r = gamma_trace(t)
     assert r.equals(4*p2*p2*p2*p2)
+
+
+def test_bug_13636():
+    """Test issue 13636 regarding handling traces of sums of products
+    of GammaMatrix mixed with other factors."""
+    pi, ki, pf = tensor_heads("pi, ki, pf", [LorentzIndex])
+    i0, i1, i2, i3, i4 = tensor_indices("i0:5", LorentzIndex)
+    x = Symbol("x")
+    pis = pi(i2) * G(-i2)
+    kis = ki(i3) * G(-i3)
+    pfs = pf(i4) * G(-i4)
+
+    a = pfs * G(i0) * kis * G(i1) * pis * G(-i1) * kis * G(-i0)
+    b = pfs * G(i0) * kis * G(i1) * pis * x * G(-i0) * pi(-i1)
+    ta = gamma_trace(a)
+    tb = gamma_trace(b)
+    t_a_plus_b = gamma_trace(a + b)
+    assert ta == 4 * (
+        -4 * ki(i0) * ki(-i0) * pf(i1) * pi(-i1)
+        + 8 * ki(i0) * ki(i1) * pf(-i0) * pi(-i1)
+    )
+    assert tb == -8 * x * ki(i0) * pf(-i0) * pi(i1) * pi(-i1)
+    assert t_a_plus_b == ta + tb