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

Escape underscores when converting to latex #1385

Merged
merged 5 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pytket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def package(self):
cmake.install()

def requirements(self):
self.requires("tket/1.2.122@tket/stable")
self.requires("tket/1.2.123@tket/stable")
self.requires("tklog/0.3.3@tket/stable")
self.requires("tkrng/0.3.3@tket/stable")
self.requires("tkassert/0.3.4@tket/stable")
Expand Down
4 changes: 4 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Features:
* Add two new status values for circuits on backends: "CANCELLING" and "RETRYING".
* Use `lark` package instead of deprecated `lark-parser`.

Fixes:

* Escape underscores in qubit and bit names when converting to latex.

1.27.0 (April 2024)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion tket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class TketConan(ConanFile):
name = "tket"
version = "1.2.122"
version = "1.2.123"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down
7 changes: 5 additions & 2 deletions tket/src/Circuit/latex_drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <boost/algorithm/string/replace.hpp>
#include <limits>

#include "tket/Circuit/Boxes.hpp"
Expand Down Expand Up @@ -287,14 +288,16 @@ std::string Circuit::to_latex_str() const {
unsigned n_lines = lines.size();
line_ids.insert({qb, n_lines});
LineBufferInfo& line = *lines.emplace(lines.end());
line.buffer << "\\lstick{" + qb.repr() + "} & ";
line.buffer << "\\lstick{" +
boost::replace_all_copy(qb.repr(), "_", "\\_") + "} & ";
line.is_quantum = true;
}
for (const Bit& cb : this->all_bits()) {
unsigned n_lines = lines.size();
line_ids.insert({cb, n_lines});
LineBufferInfo& line = *lines.emplace(lines.end());
line.buffer << "\\lstick{" + cb.repr() + "} & ";
line.buffer << "\\lstick{" +
boost::replace_all_copy(cb.repr(), "_", "\\_") + "} & ";
line.is_quantum = false;
}

Expand Down
8 changes: 8 additions & 0 deletions tket/test/src/Circuit/test_Circ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "tket/Transformations/Replacement.hpp"
#include "tket/Transformations/Transform.hpp"
#include "tket/Utils/MatrixAnalysis.hpp"
#include "tket/Utils/UnitID.hpp"

namespace tket {
namespace test_Circ {
Expand Down Expand Up @@ -2694,6 +2695,13 @@ SCENARIO("Confirm that LaTeX output compiles", "[latex][.long]") {
c.add_conditional_gate<unsigned>(
OpType::CU3, {1.04, 0.36, -0.36}, {0, 4}, {}, 0);

// https://github.com/CQCL/tket/issues/1363
Qubit q1("q_1", 0);
Bit c1("c_1", 0);
c.add_qubit(q1);
c.add_bit(c1);
c.add_measure(q1, c1);

c.to_latex_file("circ.tex");
int response = std::system("latexmk -pdf circ.tex -quiet");
REQUIRE(response == 0);
Expand Down
Loading