Skip to content

Commit

Permalink
Update MathJax to 2.7.5; create option to use Linux system version
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmassay committed Feb 23, 2019
1 parent 0136255 commit 568aba5
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 15 deletions.
38 changes: 30 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,9 @@ source_group( "Source Updates" FILES ${SOURCEUPDATE_FILES} )

set( ALL_SOURCES ${RAW_SOURCES} ${UI_FILES_H} ${QRC_FILES_CPP} ${QM_FILES} )

# Location of the MathJax zip archive for all platforms
set( MATHJAX_ZIP "${CMAKE_SOURCE_DIR}/src/Resource_Files/polyfills/ML.zip" )

# Adding resource (RC) files for Windows
if ( WIN32 )
configure_file( Resource_files/windows/version.rc.in ${PROJECT_BINARY_DIR}/version.rc )
Expand All @@ -606,7 +609,8 @@ if( APPLE )
if( CMAKE_GENERATOR STREQUAL Xcode )
exec_program("mkdir -p ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/Sigil.app/Contents/Resources")
exec_program("mkdir -p ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/Sigil.app/Contents/polyfills")
exec_program("cp ${PROJECT_SOURCE_DIR}/Resource_Files/polyfills/MathJax.js ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/Sigil.app/Contents/polyfills")
#exec_program("cp ${PROJECT_SOURCE_DIR}/Resource_Files/polyfills/MathJax.js ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/Sigil.app/Contents/polyfills")
exec_program("unzip ${MATHJAX_ZIP} -d ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/Sigil.app/Contents/polyfills")
exec_program("cp ${PROJECT_SOURCE_DIR}/Resource_Files/icon/Sigil.icns ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/Sigil.app/Contents/Resources")
exec_program("cp ${PROJECT_SOURCE_DIR}/Resource_Files/icon/sgf.icns ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/Sigil.app/Contents/Resources")
exec_program("cp ${PROJECT_SOURCE_DIR}/Resource_Files/icon/epub.icns ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/Sigil.app/Contents/Resources")
Expand All @@ -621,7 +625,8 @@ if( APPLE )
else()
exec_program("mkdir -p ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Sigil.app/Contents/Resources")
exec_program("mkdir -p ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Sigil.app/Contents/polyfills")
exec_program("cp ${PROJECT_SOURCE_DIR}/Resource_Files/polyfills/MathJax.js ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Sigil.app/Contents/polyfills")
#exec_program("cp ${PROJECT_SOURCE_DIR}/Resource_Files/polyfills/MathJax.js ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Sigil.app/Contents/polyfills")
exec_program("unzip ${MATHJAX_ZIP} -d ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Sigil.app/Contents/polyfills")
exec_program("cp ${PROJECT_SOURCE_DIR}/Resource_Files/icon/Sigil.icns ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Sigil.app/Contents/Resources")
exec_program("cp ${PROJECT_SOURCE_DIR}/Resource_Files/icon/sgf.icns ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Sigil.app/Contents/Resources")
exec_program("cp ${PROJECT_SOURCE_DIR}/Resource_Files/icon/epub.icns ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Sigil.app/Contents/Resources")
Expand Down Expand Up @@ -841,10 +846,10 @@ elseif (MSVC)
endif()
endforeach( QM )

# Copy the MathJax polyfill
set( MATHJAX_FILE ${CMAKE_SOURCE_DIR}/src/Resource_Files/polyfills/MathJax_win.js )
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD COMMAND cmake -E make_directory ${MAIN_PACKAGE_DIR}/polyfills/ )
add_custom_command( TARGET ${TARGET_FOR_COPY} POST_BUILD COMMAND cmake -E copy ${MATHJAX_FILE} ${MAIN_PACKAGE_DIR}/polyfills/MathJax.js )
# Extract the MathJax polyfill archive into the package directory
set( MATHJAX_UNZIP_DEST ${MAIN_PACKAGE_DIR}/polyfills )
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD COMMAND cmake -E make_directory ${MATHJAX_UNZIP_DEST} )
add_custom_command( TARGET ${TARGET_FOR_COPY} POST_BUILD COMMAND cmake -E tar xzf ${MATHJAX_ZIP} WORKING_DIECTORY ${MATHJAX_UNZIP_DEST} )

# Copy the dictionary files
add_custom_command( TARGET ${TARGET_FOR_COPY} PRE_BUILD COMMAND cmake -E make_directory ${MAIN_PACKAGE_DIR}/hunspell_dictionaries/ )
Expand Down Expand Up @@ -958,12 +963,25 @@ if( UNIX AND NOT APPLE )
set_property (
SOURCE sigil_constants.cpp
PROPERTY COMPILE_DEFINITIONS
SIGIL_SHARE_ROOT="${SIGIL_SHARE_ROOT}" DICTS_ARE_BUNDLED=${INSTALL_BUNDLED_DICTS} EXTRA_DICT_DIRS="${EXTRA_DICT_DIRS}"
SIGIL_SHARE_ROOT="${SIGIL_SHARE_ROOT}" DICTS_ARE_BUNDLED=${INSTALL_BUNDLED_DICTS}
EXTRA_DICT_DIRS="${EXTRA_DICT_DIRS}" MATHJAX_DIR="${MATHJAX_DIR}"
)

# Launch script for sigil
set( LINUX_LAUNCH_INSTALL_SCRIPT_CONFIGURED ${CMAKE_BINARY_DIR}/sigil-sh_install_configured )
set( SIGIL_EXECUTABLE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX} )

# Destination directory for unzipped MathJax archive
set( MATHJAX_UNZIP_DEST "${CMAKE_BINARY_DIR}/polyfills" )
# Remove previous directories
if ( EXISTS ${MATHJAX_UNZIP_DEST} )
file( REMOVE_RECURSE ${MATHJAX_UNZIP_DEST} )
endif()
# Create the polyfills dir and extract the MathJax archive to it
if ( NOT DEFINED MATHJAX_DIR )
file( MAKE_DIRECTORY ${MATHJAX_UNZIP_DEST} )
execute_process( COMMAND cmake -E tar xvzf ${MATHJAX_ZIP} WORKING_DIRECTORY ${MATHJAX_UNZIP_DEST} )
endif()

# Configure Linux launch script
configure_file( ${LINUX_LAUNCH_INSTALL_SCRIPT} ${LINUX_LAUNCH_INSTALL_SCRIPT_CONFIGURED} )
Expand Down Expand Up @@ -997,7 +1015,11 @@ if( UNIX AND NOT APPLE )
if ( INSTALL_BUNDLED_DICTS )
install( FILES ${DIC_FILES} DESTINATION ${SIGIL_SHARE_ROOT}/hunspell_dictionaries/ )
endif()
install( FILES ${CMAKE_SOURCE_DIR}/src/Resource_Files/polyfills/MathJax.js DESTINATION ${SIGIL_SHARE_ROOT}/polyfills/ )
if ( MATHJAX_DIR )
install( FILES ${CMAKE_SOURCE_DIR}/src/Resource_Files/polyfills/SIGIL_EBOOK_MML_SVG.js DESTINATION ${MATHJAX_DIR}/config/local/ )
else()
install( DIRECTORY ${MATHJAX_UNZIP_DEST}/MJ/ DESTINATION ${SIGIL_SHARE_ROOT}/polyfills/MJ )
endif()
install( DIRECTORY ${CMAKE_SOURCE_DIR}/src/Resource_Files/plugin_launchers/python/ DESTINATION ${SIGIL_SHARE_ROOT}/plugin_launchers/python )
install( DIRECTORY ${CMAKE_SOURCE_DIR}/src/Resource_Files/python3lib/ DESTINATION ${SIGIL_SHARE_ROOT}/python3lib )
install( FILES ${EXAMPLE_FILES} DESTINATION ${SIGIL_SHARE_ROOT}/examples/ )
Expand Down
21 changes: 14 additions & 7 deletions src/MainUI/PreviewWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,24 +206,31 @@ void PreviewWindow::UpdatePage(QString filename, QString text, QList<ViewEditor:
// On Mac OS X QCoreApplication::applicationDirPath() points to Sigil.app/Contents/MacOS/
QDir execdir(QCoreApplication::applicationDirPath());
execdir.cdUp();
mathjaxurl = execdir.absolutePath() + "/polyfills/MathJax.js";
mathjaxurl = execdir.absolutePath() + "/polyfills/MJ/MathJax.js";
#elif defined(Q_OS_WIN32)
mathjaxurl = "/" + QCoreApplication::applicationDirPath() + "/polyfills/MathJax.js";
mathjaxurl = "/" + QCoreApplication::applicationDirPath() + "/polyfills/MJ/MathJax.js";
#else
// all flavours of linux / unix
// user supplied environment variable to 'share/sigil' directory will overrides everything
if (!sigil_extra_root.isEmpty()) {
mathjaxurl = sigil_extra_root + "/polyfills/MathJax.js";
// First check if system MathJax was configured to be used at compile time
if (!mathjax_dir.isEmpty()) {
mathjaxurl = mathjax_dir + "/MathJax.js";
} else {
mathjaxurl = sigil_share_root + "/polyfills/MathJax.js";
// otherwise user supplied environment variable to 'share/sigil'
// takes precedence over Sigil's usual share location.
if (!sigil_extra_root.isEmpty()) {
mathjaxurl = sigil_extra_root + "/polyfills/MJ/MathJax.js";
} else {
mathjaxurl = sigil_share_root + "/polyfills/MJ/MathJax.js";
}
}
#endif

mathjaxurl = "file://" + Utility::URLEncodePath(mathjaxurl);
mathjaxurl = mathjaxurl + "?config=local/SIGIL_EBOOK_MML_SVG";
int endheadpos = text.indexOf("</head>");
if (endheadpos > 1) {
QString inject_mathjax =
"<script type=\"text/javascript\" "
"<script type=\"text/javascript\" async=\"async\" "
"src=\"" + mathjaxurl + "\"></script>";
text.insert(endheadpos, inject_mathjax);
}
Expand Down
Binary file added src/Resource_Files/polyfills/ML.zip
Binary file not shown.
23 changes: 23 additions & 0 deletions src/Resource_Files/polyfills/SIGIL_EBOOK_MML_SVG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*************************************************************
*
* Modified Version of MathJax/unpacked/config/MML_SVG.js
* Specifically for Sigil-EBook's PreviewWindow
*
* Copyright (c) 2010-2018 The MathJax Consortium
*
* Part of the MathJax library.
* See http://www.mathjax.org for details.
*
* Licensed under the Apache License, Version 2.0;
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*/

MathJax.Hub.Config({
extensions: ["mml2jax.js","MathML/mml3.js","MathEvents.js","fast-preview.js","AssistiveMML.js"],
jax: ["input/MathML","output/SVG","output/PreviewHTML"],
messageStyle: "none"
});

MathJax.Ajax.loadComplete("[MathJax]/config/local/SIGIL_EBOOK_MML_SVG.js");
1 change: 1 addition & 0 deletions src/sigil_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const QString hunspell_dicts_override = QString(getenv("SIGIL_DICTIONARIES"));
const QString sigil_share_root = QString(SIGIL_SHARE_ROOT);
const bool dicts_are_bundled = DICTS_ARE_BUNDLED;
const QString extra_dict_dirs = QString(EXTRA_DICT_DIRS);
const QString mathjax_dir = QString(MATHJAX_DIR);
const QString PYTHON_MAIN_PATH = "/python3/lib/python3.5";
#if __x86_64__ || __ppc64__
const QStringList PYTHON_SYS_PATHS = QStringList () << "/plat-x86_64-linux-gnu" << "/plat-linux" << "/lib-dynload" << "/site-packages";
Expand Down
1 change: 1 addition & 0 deletions src/sigil_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ extern const QString hunspell_dicts_override;
extern const QString sigil_share_root;
extern const bool dicts_are_bundled;
extern const QString extra_dict_dirs;
extern const QString mathjax_dir;
#endif

#endif // SG_CONSTANTS_H

3 comments on commit 568aba5

@eli-schwartz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding this! I've successfully tested it on my Arch Linux packages.

@dougmassay
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Thanks for reporting back on it. I was going to give you a heads-up when I finished updating the documentation, but I'm glad it checks out.

@eli-schwartz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.