Skip to content

change color #44

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

Open
archievega opened this issue Jan 28, 2022 · 4 comments
Open

change color #44

archievega opened this issue Jan 28, 2022 · 4 comments

Comments

@archievega
Copy link

How to change color of formula? I've tried almost everything

@PankajPunia
Copy link

PankajPunia commented Jun 24, 2022

@em1tao
Try passing styles like below:

const defaultOptions = {
  messageStyle: 'none',
  extensions: ['tex2jax.js'],
  jax: ['input/TeX', 'output/HTML-CSS'],
  tex2jax: {
    inlineMath: [
      ['$', '$'],
      ['\\(', '\\)'],
    ],
    displayMath: [
      ['$$', '$$'],
      ['\\[', '\\]'],
    ],
    processEscapes: true,
  },
  TeX: {
    extensions: [
      'AMSmath.js',
      'AMSsymbols.js',
      'noErrors.js',
      'noUndefined.js',
    ],
  },
};

const MathHtml: React.FC<MathHtmlProps> = ({
  html,
  webViewStyles,
  mathJaxStyles = {'background-color': 'white', color: 'black'},
  scrollEnabled = true,
  fontSize,
}) => {
  const [height, setHeight] = useState(1);
  const mathJaxOptions = {
    styles: {
      '#formula': {
        'font-size': fontSize,
        ...mathJaxStyles,
      },
    },
  };
  const wrapMathjax = (content: string) => {
    const options = JSON.stringify(
      Object.assign({}, defaultOptions, mathJaxOptions),
    );

    return `
			<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
			<script type="text/x-mathjax-config">
				MathJax.Hub.Config(${options});

				MathJax.Hub.Queue(function() {
					var height = document.documentElement.scrollHeight;
					window.ReactNativeWebView.postMessage(String(height));
					document.getElementById("formula").style.visibility = '';
				});
			</script>

			<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
			<div id="formula" style="visibility: hidden;">
				${content}
			</div>
		`;
  };

  const sourceHtml = wrapMathjax(html);

  const handleMessage = (message: WebViewMessageEvent) => {
    setHeight(Number(message.nativeEvent.data));
  };

  return (
    <WebView
      scrollEnabled={scrollEnabled}
      showsVerticalScrollIndicator={false}
      showsHorizontalScrollIndicator={false}
      onMessage={handleMessage}
      source={{html: sourceHtml}}
      containerStyle={{height}}
      style={[styles.viewStyles, webViewStyles]}
      androidHardwareAccelerationDisabled={true}
    />
  );
};

const styles = StyleSheet.create({
  viewStyles: {
    opacity: 0.99,
    overflow: 'hidden',
    flex: 1,
  },
});

export default MathHtml;

@sickopickle
Copy link

sickopickle commented Apr 17, 2023

I think your code is cut off can you please edit it @PankajPunia

@PankajPunia
Copy link

@sickopickle done.

@sickopickle
Copy link

@PankajPunia thank you! I've decided to just use react-native-math-view instead.

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

No branches or pull requests

3 participants